Admob plugin for ionic ios - ios

I am working in an project with both platforms like android and ios, i have to implement banner ads in my project. I have tried various plugin to implement the banner ads.
I have tried the below link for android and ios, it working well with android but after adding this plugin my app shows error,
https://www.codeproject.com/Articles/1005149/Adding-AdMob-to-Ionic-Framework-Application-Step-B
plugin name - cordova-plugin-admob
After adding the plugin, i have use the command 'ionic build ios', which returns - Error code 65 for command: xcodebuild with args: -xcconfig,
Don't know the exact reason of this issue.

Atlast I have findout the solution to load Ads in ionic app,
Please add the plugin
cordova plugin add cordova-plugin-admobpro
Add the below code in your html page,
//Script tag to load jquery1.9.js-
<script type="text/javascript" src="jquery-1.9.js"></script>
<script>
var admobid = {};
if( /(android)/i.test(navigator.userAgent) ) {
admobid = { // for Android
banner: 'ca-app-pub-6869992474017983/9375997553',
interstitial: 'ca-app-pub-6869992474017983/1657046752'
};} else if(/(ipod|iphone|ipad)/i.test(navigator.userAgent)) {
admobid = { // for iOS
banner: 'ca-app-pub-6869992474017983/4806197152',
interstitial: 'ca-app-pub-6869992474017983/7563979554'
};} else {
admobid = { // for Windows Phone
banner: 'ca-app-pub-6869992474017983/8878394753',
interstitial: 'ca-app-pub-6869992474017983/1355127956'
};}function createSelectedBanner(){
//alert("banner");
if(AdMob) AdMob.createBanner({
adId: admobid.banner,
overlap: $('#overlap').is(':checked'),
offsetTopBar: $('#offsetTopBar').is(':checked'),
adSize: 'BANNER',
position: AdMob.AD_POSITION.BOTTOM_CENTER,
});}function showBannerAtPosition(){
if(AdMob) AdMob.showBanner( $('#adPosition').val() );}function onDeviceReady() {
if (! AdMob) {
//alert( 'admob plugin not ready' );
return;
}
initAd();
// display a banner at startup
createSelectedBanner();}function initAd(){//alert("init");
AdMob.getAdSettings(function(info){
console.log('adId: ' + info.adId + '\n' + 'adTrackingEnabled: ' + info.adTrackingEnabled);}, function(){
console.log('failed to get user ad settings');
});
AdMob.setOptions({
adSize: 'BANNER',
position: AdMob.AD_POSITION.BOTTOM_CENTER,
isTesting: true, // set to true, to receiving test ad for testing purpose
bgColor: 'black', // color name, or '#RRGGBB'
// autoShow: true // auto show interstitial ad when loaded, set to false if prepare/show
// offsetTopBar: false, // avoid overlapped by status bar, for iOS7+
});
// new events, with variable to differentiate: adNetwork, adType, adEvent
$(document).on('onAdFailLoad', function(e){
// when jquery used, it will hijack the event, so we have to get data from original event
if(typeof e.originalEvent !== 'undefined') e = e.originalEvent;
var data = e.detail || e.data || e;
//alert('error: ' + data.error +', reason: ' + data.reason +', adNetwork:' + data.adNetwork +', adType:' + data.adType +', adEvent:' + data.adEvent); // adType: 'banner', 'interstitial', etc.
});
$(document).on('onAdLoaded', function(e){
});
$(document).on('onAdPresent', function(e){
});
$(document).on('onAdLeaveApp', function(e){
});
$(document).on('onAdDismiss', function(e){
});
$('#btn_create').click(createSelectedBanner);
$('#btn_remove').click(function(){
AdMob.removeBanner();
});
$('#btn_show').click(showBannerAtPosition);
$('#btn_hide').click(function(){
AdMob.hideBanner();
});
// test interstitial ad
$('#btn_prepare').click(function(){
AdMob.prepareInterstitial({
adId:admobid.interstitial,
autoShow: $('#autoshow').is(':checked'),
});
});
$('#btn_showfull').click(function(){
AdMob.showInterstitial();
});
// test case for #256, https://github.com/floatinghotpot/cordova-admob-pro/issues/256
$(document).on('backbutton', function(){
if(window.confirm('Are you sure to quit?')) navigator.app.exitApp();
});$(document).ready(function()
{
//alert("start");
// on mobile device, we must wait the 'deviceready' event fired by cordova
if(/(ipad|iphone|ipod|android|windows phone)/i.test(navigator.userAgent)) {
document.addEventListener('deviceready', onDeviceReady, false);
} else {
onDeviceReady();
}
});
</script>

Related

phonegap push notification works on android but not on ios

As the title says Push notification works fine on android but on IOS it does not. push.on(registration...) is never called. I have made sure that provisional profiles are valid for both development and distribution. I am using firebase for cloud messaging.I am looking for any sort of guidance on how to fix this.
Here is the console out put:
2017-03-23 16:15:49.741405 [342:34586] Push Plugin register called
2017-03-23 16:15:49.741515 [342:34586] PushPlugin.register: setting badge to false
2017-03-23 16:15:49.741559 [342:34586] PushPlugin.register: clear badge is set to 0
2017-03-23 16:15:49.752879 [342:33926] Push Plugin register success: <######## ######## ######## ######## ######## ######## ######## ########>
.
document.addEventListener("deviceready", function() {
var push = PushNotification.init({
android: {
senderID: "############",
forceShow: true
},
ios: {
sound: true,
alert: true,
badge: true
}
});
push.on('registration', function(data) {
console.log('GCM: ' + data.registrationId);
$rootScope.pushRegStatus = true;
$rootScope.registerPushOnServer(data.registrationId);
});
push.on('notification', function(data) {
// data.message,
// data.title,
// data.count,
// data.sound,
// data.image,
// data.additionalData
// console.log('notification' + data.toString());
// App started by clicking on push notification ..
// if(data.additionalData.coldstart === false || data.additionalData.coldstart === true) {
// $location.path('/pushLog/' + data.additionalData.push_log_id);
// }
// Got notification while app is in foreground ..
if(data.additionalData.foreground) {
//$rootScope.alert(data.title, data.message);
} else {
$rootScope.alert(data.title, data.message);
// $location.path('/pushLog/' + data.additionalData.push_log_id);
$rootScope.openPushLogFromNotification = true;
// setTimeout(function() {
// $rootScope.openPushLogFromNotification = false;
// }, 3000);
$location.path('/pushLog');
}
});
push.on('error', function(e) {
// e.message
console.log(e);
});
}, false);
I fixed it by skiping firebase all together and going straight to APNS

Looking for a complete tutorial about process to update an electron app installed

I have read lots of things about this subjet but i can't find a complete documentation.
I succeeded to use electron-packager and electron-winstaller to get a setup.exe for my electron application.
I used electron-release-server to create a server to host my electron app to deploy.
I add in my electron app this peace of code
const autoUpdater = electron.autoUpdater;
var feedUrl = 'http://10.61.32.53:1337//download/:' + app.getVersion();
autoUpdater.setFeedURL(feedUrl);
// event handling after download new release
autoUpdater.on('update-downloaded', function (event, releaseNotes, releaseName, releaseDate, updateUrl, quitAndUpdate) {
// confirm install or not to user
var index = dialog.showMessageBox(mainWindow, {
type: 'info',
buttons: [i18n.__('Restart'), i18n.__('Later')],
title: "Typetalk",
message: i18n.__('The new version has been downloaded. Please restart the application to apply the updates.'),
detail: releaseName + "\n\n" + releaseNotes
});
if (index === 1) {
return;
}
// restart app, then update will be applied
quitAndUpdate();
} );
But when i install my application, i have this error :
In fact, i think i don't understand what to do client side but server side as well. Any help would be very appreciated !
Thanks in advance
I used following in my version and that works (except the Tray Icon):
app.on('ready', () => {
console.warn("Starting Autoupdater")
console.warn(app.getVersion())
var feedUrl = 'http://ls-desktop.herokuapp.com/update/' + os.platform() + '/' + app.getVersion() + '/';
autoUpdater.setFeedURL(feedUrl);
tray = new Tray(__dirname + '/LS.png')
console.log(__dirname + '/LS.png')
console.log('created');
autoUpdater.on('checking-for-update', function() {
tray.displayBalloon({
title: 'Autoupdater',
content: 'Checking for Update!'
})
});
autoUpdater.on('update-available', function() {
console.log("update-available");
});
autoUpdater.on('update-not-available', function() {
tray.displayBalloon({
title: 'Autoupdater',
content: 'No Updates availible!'
})
});
autoUpdater.on('update-downloaded', function() {
console.log(" update-downloaded");
});
setTimeout(function() {autoUpdater.checkForUpdates()}, 10000);
autoUpdater.on('update-downloaded', function (event, releaseNotes, releaseName, releaseDate, updateUrl, quitAndUpdate) {
var index = dialog.showMessageBox({
type: 'info',
buttons: ['Restart', 'Later'],
title: "Lornsenschule Vertretungsplan",
message: ('The new version has been downloaded. Please restart the application to apply the updates.'),
detail: releaseName + "\n\n" + releaseNotes
});
if (index === 1) {
return;
}
quitAndUpdate()
});
})
Note the setTimeout(function() {autoUpdater.checkForUpdates()}, 10000); that is the real workaround that I used. the rest is just an nice Addition I think

Notifications not working with ios8 - Pushwoosh + phonegap

4 apps in apple store and android market created with pushwoosh + phonegap build. Notifications works good on all devices except for new ios8. why? is sometheing changed? I used these 2 files:
Pushnotification.js
(function(cordova) {
function PushNotification() {}
// Call this to register for push notifications and retreive a deviceToken
PushNotification.prototype.registerDevice = function(config, success, fail) {
cordova.exec(success, fail, "PushNotification", "registerDevice", config ? [config] : []);
};
// Call this to set tags for the device
PushNotification.prototype.setTags = function(config, success, fail) {
cordova.exec(success, fail, "PushNotification", "setTags", config ? [config] : []);
};
// Call this to send geo location for the device
PushNotification.prototype.sendLocation = function(config, success, fail) {
cordova.exec(success, fail, "PushNotification", "sendLocation", config ? [config] : []);
};
PushNotification.prototype.onDeviceReady = function() {
cordova.exec(null, null, "PushNotification", "onDeviceReady", []);
};
// Call this to get tags for the device
PushNotification.prototype.getTags = function(success, fail) {
cordova.exec(success, fail, "PushNotification", "getTags", []);
};
//Android Only----
PushNotification.prototype.unregisterDevice = function(success, fail) {
cordova.exec(success, fail, "PushNotification", "unregisterDevice", []);
};
//config params: {msg:"message", seconds:30, userData:"optional"}
PushNotification.prototype.createLocalNotification = function(config, success, fail) {
cordova.exec(success, fail, "PushNotification", "createLocalNotification", config ? [config] : []);
};
PushNotification.prototype.clearLocalNotification = function() {
cordova.exec(null, null, "PushNotification", "clearLocalNotification", []);
};
//advanced background task to track device position and not drain the battery
PushNotification.prototype.startGeoPushes = function(success, fail) {
cordova.exec(success, fail, "PushNotification", "startGeoPushes", []);
};
PushNotification.prototype.stopGeoPushes = function(success, fail) {
cordova.exec(success, fail, "PushNotification", "stopGeoPushes", []);
};
//sets multi notification mode on
PushNotification.prototype.setMultiNotificationMode = function(success, fail) {
cordova.exec(success, fail, "PushNotification", "setMultiNotificationMode", []);
};
//sets single notification mode
PushNotification.prototype.setSingleNotificationMode = function(success, fail) {
cordova.exec(success, fail, "PushNotification", "setSingleNotificationMode", []);
};
//type: 0 default, 1 no sound, 2 always
PushNotification.prototype.setSoundType = function(type, success, fail) {
cordova.exec(success, fail, "PushNotification", "setSoundType", [type]);
};
//type: 0 default, 1 no vibration, 2 always
PushNotification.prototype.setVibrateType = function(type, success, fail) {
cordova.exec(success, fail, "PushNotification", "setVibrateType", [type]);
};
PushNotification.prototype.setLightScreenOnNotification = function(on, success, fail) {
cordova.exec(success, fail, "PushNotification", "setLightScreenOnNotification", [on]);
};
//set to enable led blinking when notification arrives and display is off
PushNotification.prototype.setEnableLED = function(on, success, fail) {
cordova.exec(success, fail, "PushNotification", "setEnableLED", [on]);
};
//{goal:'name', count:3} (count is optional)
PushNotification.prototype.sendGoalAchieved = function(config, success, fail) {
cordova.exec(success, fail, "PushNotification", "sendGoalAchieved", config ? [config] : []);
};
//Android End----
//iOS only----
PushNotification.prototype.startLocationTracking = function(backgroundMode, success, fail) {
cordova.exec(success, fail, "PushNotification", "startLocationTracking", backgroundMode ? [{mode : backgroundMode}] : []);
};
PushNotification.prototype.stopLocationTracking = function(success, fail) {
cordova.exec(success, fail, "PushNotification", "stopLocationTracking", []);
};
// Call this to get a detailed status of remoteNotifications
PushNotification.prototype.getRemoteNotificationStatus = function(callback) {
cordova.exec(callback, callback, "PushNotification", "getRemoteNotificationStatus", []);
};
// Call this to set the application icon badge
PushNotification.prototype.setApplicationIconBadgeNumber = function(badgeNumber, callback) {
cordova.exec(callback, callback, "PushNotification", "setApplicationIconBadgeNumber", [{badge: badgeNumber}]);
};
// Call this to clear all notifications from the notification center
PushNotification.prototype.cancelAllLocalNotifications = function(callback) {
cordova.exec(callback, callback, "PushNotification", "cancelAllLocalNotifications", []);
};
//iOS End----
// Event spawned when a notification is received while the application is active
PushNotification.prototype.notificationCallback = function(notification) {
var ev = document.createEvent('HTMLEvents');
ev.notification = notification;
ev.initEvent('push-notification', true, true, arguments);
document.dispatchEvent(ev);
};
cordova.addConstructor(function() {
if(!window.plugins) window.plugins = {};
window.plugins.pushNotification = new PushNotification();
});
})(window.cordova || window.Cordova || window.PhoneGap);
And app.js
function registerPushwooshIOS() {
var pushNotification = window.plugins.pushNotification;
//push notifications handler
document.addEventListener('push-notification', function(event) {
var notification = event.notification;
//navigator.notification.alert(notification.aps.alert);
//to view full push payload
//navigator.notification.alert(JSON.stringify(notification));
//reset badges on icon
pushNotification.setApplicationIconBadgeNumber(0);
});
pushNotification.registerDevice({alert:true, badge:true, sound:true, pw_appid:"69620-5C1D0", appname:"Maxistore"},
function(status) {
var deviceToken = status['deviceToken'];
console.warn('registerDevice: ' + deviceToken);
onPushwooshiOSInitialized(deviceToken);
},
function(status) {
console.warn('failed to register : ' + JSON.stringify(status));
navigator.notification.alert(JSON.stringify(['failed to register ', status]));
});
//reset badges on start
pushNotification.setApplicationIconBadgeNumber(0);
}
function onPushwooshiOSInitialized(pushToken)
{
var pushNotification = window.plugins.pushNotification;
//retrieve the tags for the device
pushNotification.getTags(function(tags) {
console.warn('tags for the device: ' + JSON.stringify(tags));
},
function(error) {
console.warn('get tags error: ' + JSON.stringify(error));
});
//start geo tracking. PWTrackSignificantLocationChanges - Uses GPS in foreground, Cell Triangulation in background.
pushNotification.startLocationTracking('PWTrackSignificantLocationChanges',
function() {
console.warn('Location Tracking Started');
});
}
function registerPushwooshAndroid() {
var pushNotification = window.plugins.pushNotification;
//push notifications handler
document.addEventListener('push-notification', function(event) {
var title = event.notification.title;
var userData = event.notification.userdata;
//dump custom data to the console if it exists
if(typeof(userData) != "undefined") {
console.warn('user data: ' + JSON.stringify(userData));
}
//and show alert
//navigator.notification.alert(title);
//stopping geopushes
pushNotification.stopGeoPushes();
});
//projectid: "GOOGLE_PROJECT_ID", appid : "PUSHWOOSH_APP_ID"
pushNotification.registerDevice({ projectid: "863823034249", appid : "69620-5C1D0" },
function(token) {
alert(token);
//callback when pushwoosh is ready
onPushwooshAndroidInitialized(token);
},
function(status) {
alert("failed to register: " + status);
console.warn(JSON.stringify(['failed to register ', status]));
});
}
function onPushwooshAndroidInitialized(pushToken)
{
//output the token to the console
console.warn('push token: ' + pushToken);
var pushNotification = window.plugins.pushNotification;
pushNotification.getTags(function(tags) {
console.warn('tags for the device: ' + JSON.stringify(tags));
},
function(error) {
console.warn('get tags error: ' + JSON.stringify(error));
});
//set multi notificaiton mode
//pushNotification.setMultiNotificationMode();
//pushNotification.setEnableLED(true);
//set single notification mode
//pushNotification.setSingleNotificationMode();
//disable sound and vibration
//pushNotification.setSoundType(1);
//pushNotification.setVibrateType(1);
pushNotification.setLightScreenOnNotification(false);
//goal with count
//pushNotification.sendGoalAchieved({goal:'purchase', count:3});
//goal with no count
//pushNotification.sendGoalAchieved({goal:'registration'});
//setting list tags
//pushNotification.setTags({"MyTag":["hello", "world"]});
//settings tags
pushNotification.setTags({deviceName:"hello", deviceId:10},
function(status) {
console.warn('setTags success');
},
function(status) {
console.warn('setTags failed');
});
function geolocationSuccess(position) {
pushNotification.sendLocation({lat:position.coords.latitude, lon:position.coords.longitude},
function(status) {
console.warn('sendLocation success');
},
function(status) {
console.warn('sendLocation failed');
});
};
// onError Callback receives a PositionError object
//
function geolocationError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
function getCurrentPosition() {
navigator.geolocation.getCurrentPosition(geolocationSuccess, geolocationError);
}
//greedy method to get user position every 3 second. works well for demo.
// setInterval(getCurrentPosition, 3000);
//this method just gives the position once
// navigator.geolocation.getCurrentPosition(geolocationSuccess, geolocationError);
//this method should track the user position as per Phonegap docs.
// navigator.geolocation.watchPosition(geolocationSuccess, geolocationError, { maximumAge: 3000, enableHighAccuracy: true });
//Pushwoosh Android specific method that cares for the battery
pushNotification.startGeoPushes();
}
function initPushwoosh() {
var pushNotification = window.plugins.pushNotification;
if(device.platform == "Android")
{
registerPushwooshAndroid();
pushNotification.onDeviceReady();
}
if(device.platform == "iPhone" || device.platform == "iOS")
{
registerPushwooshIOS();
pushNotification.onDeviceReady();
}
}
The push notification interface changed in iOS8. If your third-party library hasn't been updated to adapt, push notifications will likely fail.
Background:
Previously, registering for notifications was done with
-[UIApplication registerForRemoteNotificationTypes:]
As of iOS8, it is now done with:
-[UIApplication registerUserNotificationSettings:]
-[UIApplication registerForRemoteNotifications]
Take a look at the pushwoosh post
Due to multiple support requests about iOS 8 we thought it’d be good to also shed some light here in our Blog. Currently, there are two version of Pushwoosh iOS SDK:
iOS 7 SDK – must be compiled with Xcode v.5 – does not support latest features introduced in iOS 8;
iOS 8 SDK – must be compiled with Xcode v.6
So, applications compiled with iOS 7 SDK in Xcode v.5 will continue working properly on devices running iOS 8 due to its compatibility. If you use Pushwoosh iOS 8 SDK, you must compile your app with Xcode v.6.
You can download it here

Phonegap show html if not connected

Here is my code at the minute:
Using phonegap 2.9
<head>
</head>
<body>
<script charset="utf-8" src="js/cordova.js"></script>
<script>
document.addEventListener("deviceready", onDeviceReady, false);
document.addEventListener("online", onOnline, false);
document.addEventListener("offline", onOffline, false);
// PhoneGap is loaded and it is now safe to make calls PhoneGap methods
//
function onDeviceReady() {
console.log("Device Ready");
}
// Handle the online event
//
function onOnline() {
document.location = 'http://app.dadad.com';
}
function onOffline() {
console.log("Offline");
}
</script>
</body>
However right now I just get a white screen whether i'm connected or not. Eventually what I would like is to display some html when the user is not connected.
So in conclusion:
Would like to fix the function as it is not working
Would like to show html when not connected.
The Online/Offline events do not fire onload. They are there for when you are in app (complete load) and then lose or gain connection. I have gotten around this by doing an initial connection check on load, like this:
function checkConnetcion() {
var networkState = navigator.connection.type;
var states = {};
states[Connection.UNKNOWN] = false;
states[Connection.ETHERNET] = true;
states[Connection.WIFI] = true;
states[Connection.CELL_2G] = true;
states[Connection.CELL_3G] = true;
states[Connection.CELL_4G] = true;
states[Connection.CELL] = true;
states[Connection.NONE] = false;
var connectionStatus = states[networkState];
if(connectionStatus) {
//Do something if connected
}
else{
//Do something if not connected
}
}
Then add this your onready function:
// PhoneGap is loaded and it is now safe to make calls PhoneGap methods
//
function onDeviceReady() {
console.log("Device Ready");
checkConnetcion();
}
You can make use of Jquery ajax and send a dummy request before sending actual request. If you get and Error Code as '0' it means there is no internet connectivity.
$.ajax({
url: 'TestUrl',
type: 'GET',
success: function (data) {
// Go ahead with you request
},
error: function (x, y, z) {
if (x.status == 0) {
alert("Please connect to the internet");
}
else{
alert("Other Error Occured")
}
}
});
Secondly you can also make you of HTML 5 navigator
var condition = navigator.onLine ? "ONLINE" : "OFFLINE";
But it will show ONLINE when WIFI doesn't provide Internet connection.
Cordova connection object will also show WIFI if there is no internet connection

Phonegap:Childbrowser not working

I am working with ios phonegap application. I created a new project with phonegap2.4.0.
It was success.But my issue is childbrowser is not coming and shows following error in console:
OPENING URL:INVALID
I have done all the steps needed to include a childbrowser in the project and it is working fine in an old phonegap project.
How can i fix the problem??
function onBodyLoad() {
document.addEventListener("deviceready", onDeviceReady,false);
}
function onDeviceReady() {
cb = ChildBrowser.install();
}
function helo() {
alert("hiiii");
cordova.exec(null,null,"ChildBrowser","showWebPage",['google.com']);
}
function onDeviceReady() {
if(window.plugins.childBrowser == null)
{
ChildBrowser.install();
}
}
Or You can use InAppBrowser instead of childbrwoser.
For close browser use ref.close();
var ref = window.open("google.com", 'random_string', 'location=no');
ref.addEventListener('loadstart', function(event) {
console.log(event.type + ' - ' + event.url);
} );
ref.addEventListener('loadstop', function(event) {
console.log(event.type + ' - ' + event.url);
} );
ref.addEventListener('exit', function(event) {
//alert(event.type);
} );
function onBodyLoad()
{
document.addEventListener("deviceready", onDeviceReady,false);
}
function onDeviceReady()
{
cb = ChildBrowser.install();
}
function helo()
{
alert("hiiii");
cordova.exec(null,null,"ChildBrowser","showWebPage",['http://google.com']);
}

Resources