my app.js :
$ionicPlatform.ready(function() {
var admobid = {};
// select the right Ad Id according to platform
if( /(android)/i.test(navigator.userAgent) ) {
admobid = { // for Android
interstitial: 'ca-app-pub-3940256099942544/1033173712'
};
} else {
admobid = { // for Windows Phone
interstitial: 'ca-app-pub-3940256099942544/1033173712'
};
}
if(window.AdMob) AdMob.prepareInterstitial({
adId:admobid.interstitial,
isTesting:true,
autoShow:false
});
my controller.js :
.controller('ChatsCtrl', function($scope, Chats) {
$scope.$on('$ionicView.beforeEnter', function(e) {
if (window.AdMob) AdMob.showInterstitial();
});
$scope.$on('$ionicView.beforeLeave', function(e) {
if (window.AdMob) AdMob.showInterstitial();
});
})
I'm building an ionic framework app for android and i need to add it a interstitial ad, it should run whenever user enters chats tab.
Here is my code, i copied most part of it from http://pointdeveloper.com/how-to-add-interstitial-ads-on-navigation-to-ionic-framework-apps/ .
I changed interstitial: 'ca-app-pub-3940256099942544/1033173712' parts with my own key but it didn't work. Where is the problem?
(I'm testing it in both my android phone(Nexus 5) and Genymotion android emulator)
The internal life cicle for interstitial ads when requestInterstitialAd is called is the following one, you can read more here: https://github.com/appfeel/admob-google-cordova/wiki/requestInterstitialAd
requestInterstitialAd();
options.autoShowInterstitial == true ? showInterstitial : raise(admob.events.onAdLoaded)
So if you have set options.autoShowInterstitial = true, then it should be automatically shown, otherwiese, you should call admob.requestInterstitialAd and wait for admob.events.onAdLoaded with atType === 'interstitial' to be raised. Then you should do something like:
document.addEventListener(admob.events.onAdLoaded, function (e) {
if (e.adType === admob.AD_TYPE.INTERSTITIAL) {
admob.showInterstitialAd();
}
});
Related
I'm using google-analytics-plugin to connect google analytics with ionic 1.
In app.js,
/* Google Analytics */
if(typeof analytics !== undefined) {
analytics.startTrackerWithId("UA-XXXXXXXXX-X");
console.log("Connected Google Analytics");
} else {
console.log("Google Analytics Unavailable");
}
In controller.js, I couldn't call 'analytics' directly, so I called 'eventListener'.
.controller('LoginCtrl', function($scope) {
document.addEventListener("deviceready", function () {
if(typeof analytics !== undefined) {
analytics.trackView("Login");
}
}, false);
}
.controller('PlaylistsCtrl', function($scope) {
document.addEventListener("deviceready", function () {
if(typeof analytics !== undefined) {
analytics.trackView("PlaylistsCtrl");
}
}, false);
}
It connected to GoogleAnalytics but don't show the pageview title. Count is increased but show two controllers as a same page.
Can anyone please tell me what should I fix to show pageview title ?
Thanks in advance!
Try to use the following to show the page title
window.ga.trackView(pagename);
I'm trying to set ng-click="ionic.Platform.exitApp()" to a button but it dosen't work, i also tried ng-click="exitApp()" and ng-click="$ionic.Platform.exitApp()"but it dosen't work either.
I'm using Ionic Creator, according to this docs http://ionicframework.com/docs/api/utility/ionic.Platform/ it should be quite simple, but i don't know how to correctly set this adjust. I also tryied to add a module into Ionic Creator as:
angular.module('app.exit', []).exit(function($scope) {
ionic.Platform.ready(function(){
// will execute when device is ready, or immediately if the device is already ready.
});
var deviceInformation = ionic.Platform.device();
var isWebView = ionic.Platform.isWebView();
var isIPad = ionic.Platform.isIPad();
var isIOS = ionic.Platform.isIOS();
var isAndroid = ionic.Platform.isAndroid();
var isWindowsPhone = ionic.Platform.isWindowsPhone();
var currentPlatform = ionic.Platform.platform();
var currentPlatformVersion = ionic.Platform.version();
ionic.Platform.exitApp(); // stops the app
});
Adding this module console log prints: "exit is not a function"
Thanks
You can always try to use this ExitApp Plugin
To use, add the plugin by cordova plugin add cordova-plugin-exitapp and then add the following code to your app.js
angular.module('XYZApp', ['ionic'])
.run(function($ionicPlatform, $ionicHistory, $rootScope) {
$ionicPlatform.ready(function() {
// For exit on back button press
$ionicPlatform.registerBackButtonAction(function(e) {
if ($rootScope.backButtonPressedOnceToExit) {
navigator.app.exitApp(); // or // ionic.Platform.exitApp(); both work
} else if ($ionicHistory.backView()) {
$ionicHistory.goBack();
} else {
$rootScope.backButtonPressedOnceToExit = true;
// "Press back button again to exit" : show toast
setTimeout(function() {
$rootScope.backButtonPressedOnceToExit = false;
}, 2000); // reset if user doesn't press back within 2 seconds, to fire exit
}
e.preventDefault();
return false;
}, 101);
});
}
Thanks Chiragh Dewan,
But it dosen't work either, i added this:
angular.module('XYZApp', []).run(function($ionicPlatform, $ionicHistory, $rootScope) {
$ionicPlatform.ready(function() {
// For exit on back button press
$ionicPlatform.registerBackButtonAction(function(e) {
if ($rootScope.backButtonPressedOnceToExit) {
navigator.app.exitApp(); // or // ionic.Platform.exitApp(); both work
} else if ($ionicHistory.backView()) {
$ionicHistory.goBack();
} else {
$rootScope.backButtonPressedOnceToExit = true;
// "Press back button again to exit" : show toast
setTimeout(function() {
$rootScope.backButtonPressedOnceToExit = false;
}, 2000); // reset if user doesn't press back within 2 seconds, to fire exit
}
e.preventDefault();
return false;
}, 101);
});
}
);
... into a new JS file called exit.js
Then i added the module XYZApp into the Ionic Creator code settings Angular modules
The last step i added the cordova-plugin-exitapp
I tryied ng-click="navigator.app.exitApp()" and ng-click="ionic.Platform.exitApp()" and none of them seems to work.
U can see the project here: https://creator.ionic.io/share/html/2d9b0126751e#/menu/contacto
Thanks
I am trying to redirect to a specific job page when there's a new applicant.
Here's the code:
app.run(function($ionicPlatform, $location) {
$ionicPlatform.ready(function() {
if (ionic.Platform.isWebView()) {
window.plugins.OneSignal
.startInit("xxxxxxxxxxxxxx", "xxxxxxxxxxxx")
.handleNotificationReceived(function(jsonData) {
console.log("/app/upcoming/" + jsonData.payload.additionalData.url);
$location.path("/app/upcoming/" + jsonData.payload.additionalData.url);
})
.endInit();
}
The console shows the correct address but it does not redirect or have any errors.
For Ionic you will need to use $state.go to redirect the user to a different page in your app.
var notificationOpenedCallback = function(result) {
var data = result.notification.payload.additionalData;
if (data && data.targetUrl) {
var state = $injector.get($state);
state.go(data.targetUrl);
}
};
window.plugins.OneSignal
.startInit("YOUR_APPID", "YOUR_GOOGLE_PROJECT_NUMBER_IF_ANDROID")
.handleNotificationOpened(notificationOpenedCallback)
.endInit();
I have a barebones chat app working on Angular and Firebase, but am having trouble working with the security rules.
I've created the following rule as a test and it works in the simulator but won't work with the object I'm passing Firebase from Angular.
{
"rules": {
"chat": {
".read": true,
".write":"newData.child('text').val() === 'test'"
}
}
}
My angular code looks as follows. $rootScope.userDing is just an object that holds the user's information upon auth.
var app = angular.module("fpl-chat", ["firebase"]);
app.controller("SampleCtrl", function($rootScope, $scope, $firebaseArray) {
var ref = new Firebase("https://glaring-torch-9680.firebaseIO.com/chat");
$scope.messages = $firebaseArray(ref);
$scope.addMessage = function() {
if ($rootScope.userDing) {
$scope.toAdd = {
text: $scope.newMessageText,
timestamp: Date.now(),
user: $rootScope.userDing.name,
imgSrc: $rootScope.userDing.imgSrc,
uid: $rootScope.userDing.uid
}
} else {
$scope.user = 'Guest';
$scope.imgSrc = 'assets/img/guest.png';
$scope.uid = 'guestUID';
}
$scope.messages.$add($scope.toAdd);
$scope.newMessageText = '';
};
});
If $scope.newMessageText is 'test' then it still doesn't allow the write operation.
The error I get is:
FIREBASE WARNING: set at /chat/-K-YU0reCudVPu_8t74s failed: permission_denied
Where am I going wrong or does anyone have any debugging tips?
{
"rules": {
"chat": {
".read": true,
"$chatMsg": {
".write": true,
".validate": "newData.child('text').val() === 'test'"
}
}
}
}
I had to add another layer of ruling for the individual chat messages, very simple really.
See: https://www.firebase.com/docs/security/quickstart.html (Part 3: Make Your Rules Dynamic)
I am getting 'AdMob' is undefined when I try to execute the code below. I am trying to use the Cordova AdMob Pro plugin, but can't get past the undefined error(s). I can't confirm if the plugin is even being loaded.
Here are the versions I'm using: AngularJS v1.3.4, Cordova v4.1.2, Ionic v1.2.8. I'm running the code on a Galaxy S5 phone running Android version 4.4.4.
I've tried adding this code in both the app.js and the controller.
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
console.log('window.cordova.plugins: ' + window.cordova.plugins); //returns object
console.log('window.cordova.plugins.AdMob: ' + window.cordova.plugins.AdMob); //returns undefined
console.log('window.AdMob: ' + window.AdMob); //returns undefined
console.log('AdMob: ' + AdMob); //returns undefined
console.log('window.AdmobAd: ' + window.AdmobAd); //returns undefined
console.log('AdmobAd: ' + AdmobAd); //returns undefined
if (window.AdMob || AdMob) {
alert('admob plugin found');
var admob_key = (device.platform == "Android") ? "ADMOB_KEY" : "IOS_PUBLISHER_KEY";
var admob = window.AdMob;
admob.createBannerView(
{
'publisherId': admob_key,
'adSize': admob.AD_SIZE.BANNER,
'bannerAtTop': false
},
function () {
admob.requestAd(
{ 'isTesting': false },
function () {
admob.showAd(true);
},
function () { console.log('failed to request ad'); }
);
},
function () { console.log('failed to create banner view'); }
);
}
});
Just went through this as well and found that the error is from trying to find 'AdMob' when that doesnt exist on if (window.AdMob || AdMob)
if you just use 'if (window.AdMob) {' you should be fine.
I just developed an AngularJS extension on top of AdMob Pro so you can interact better with this Cordova Plugin.
Here is the repository: https://github.com/santonocito/angular-admobpro
Here an example of how you can use it with Ionic:
angular.module('yourApp', ['ionic', 'admob'])
.run(function($rootScope, $state, $log, $adMob) {
$ionicPlatform.ready(function() {
// AdMob
if(window.AdMob) {
var admobid;
if (device.platform == "Android") {
admobid = { // for Android
banner: 'ca-app-pub-your-ad-key',
interstitial: 'ca-app-pub-your-ad-key'
};
} else {
admobid = { // for iOS
banner: 'ca-app-pub-your-ad-key',
interstitial: 'ca-app-pub-your-ad-key'
};
}
$adMob.createBanner( {
adId: admobid.banner,
autoShow: true,
bgColor: 'black',
position: $adMob.position.BOTTOM_CENTER
});
$adMob.prepareInterstitial({
adId: admobid.interstitial,
autoShow: false
});
}
});
});
1.install admob phonegap plugin
cordova plugin add admob
init admob plugin,init plugin after deviceready event
admob.initAdmob("admob banner ID","admob interstitial ID");
3.show admob ads
admob.showBanner(admob.BannerSize.BANNER,admob.Position.TOP_APP);//show banner at the top of app
ref:https://github.com/admob-google/admob-cordova