PushPlugin Not Asking for Permissions on iOS - ios

I'm working on setting up Push Notifications for an iOS app using the Ionic Framework but I'm running into a problem.
I added the plugin using the following
ionic plugin add https://github.com/phonegap-build/PushPlugin.git
and then added the following to my services.js file:
window.onNotificationAPN = function(event){
alert(event);
}
angular.module('starter.services', [])
.run(function($ionicPlatform){
$ionicPlatform.ready(function($scope, $window){
var tokenHandler = function(result){
alert('tokenHandler' + result);
}
var errorHandler = function(error){
alert('errohandler' + error);
}
var pushNot = window.plugins.pushNotification;
pushNot.register(
tokenHandler,
errorHandler,
{
"badge":"true",
"sound":"true",
"alert":"true",
"ecb":"onNotificationAPN"
}
);
});
})
When I run the app on my test device (running iOS 6.1.6) using command+R or sending it using testflight the application runs but never asks for permission to send push notifications and the the tokenHandler function is never called. Any help would be greatly appreciated.

Thanks for asking the question. I was searching for this for hours.
Turns out the solution for me was making sure that the opening angular module line in the app.js file included the ionic.service.core module dependency.
Then everything worked.
NOTE: (i wish it had thrown an error instead of allowing the push.register call to actually return a token)
angular.module('starter', ['ionic', 'ionic.service.core'])

The way I was able to solve this was to switch over to using ngCordova's Push script with the PushPlugin.

Related

Permission.locationAlways.isGranted always returns false ios

I am using the permission_handler package in flutter to access permissions of the underlying device that my app would run on.
My problem, however, is that the Permission.locationAlways.isGranted always returns false, even when I have changed the permission to "always allow" in the app settings.
Here's the function that checks the phone's permission using the permission_handler package:
void _checkLocationPermission() async {
bool isGranted = await Permission.locationAlways.isGranted;
print("isGranted -- $isGranted");
if (_locationPermissionGranted != isGranted) {
setState(() {
_locationPermissionGranted = isGranted;
});
}
}
This function is called in the initState() method of the screen. I would appreciate any guidance to solve this; it seems pretty simple and I don't know what I am doing wrong.
Make sure you installed the package properly on ios. Modify the podfile appropriately as explained here: here. Also, this video may help, in case you're struggling with the instructions in the previous link: video

Flutter no OAuth result from Magic Link only on iOS

I am using magic_sdk: ^0.3.1 and magic_ext_oauth: ^0.1.0 in flutter to implement a login.
This is the code I am using
try{
Magic magic = Magic.instance;
if (loginType == OAuthProvider.GOOGLE) {
Logger().w('logging with google'); //working
var configuration = OAuthConfiguration(
provider: OAuthProvider.GOOGLE,
redirectURI: 'magicauthentication://');
Logger().w('logging configuration added'); //working
var result = await magic.oauth.loginWithPopup(configuration);
Logger().w('popup passed'); //not working
Logger().w(result.magic!.toJson());
var token = result.magic!.idToken;
exchangeToken(context, token);
}
} catch (e) {
Logger().e(e); //not working
}
This code works fine without any bugs on Android. On iOS it does not. I added loggers to check the executing lines. There are marked in the above code as working and not working.
Since I had to add android schemas to work on Android I also added applinks on iOS
What can be the problem here why it is not giving result only on iOS ?
Is there anything more that I need to add?
as it is clear from the score section of it, it doesn't support multiple platforms, try the recent one.

Ionic/Cordova Social Sharing

I added the plugin to my app like so: cordova plugin add https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin.git
Here's my code in my controller:
$scope.OtherShare = function(){
window.plugins.socialsharing.share('myTitle',null,null,'sometingIShareHEre');
}
My code works well on my android device. But in iOS it only works after I exit the app then goes back to it. I tried adding $ionicPlatform.ready before/after button click but it didn't changed a thing? What am I missing?
This is strange, I am guessing this would be a device.ready issue. Try wrapping up your code in the device ready callback like
$scope.OtherShare = function(){
document.addEventListener("deviceready", function(){
window.plugins.socialsharing.share('myTitle',null,null,'sometingIShareHEre');
}, false);
}
In Ionic
$scope.OtherShare = function(){
ionic.Platform.ready(function(){
window.plugins.socialsharing.share('myTitle',null,null,'sometingIShareHEre');
});
}
Hope it helps

Cordova PushPlugin onNotificationAPN(e) callback not working or defined

I am working with Cordova / PhoneGap plugin PushPlugin and I have it setup pretty well and working, including a test .php and .pem file on my local server using a live device (iPhone 5). IOS 8. There are a couple of issues, with the main one being the call to this function in index.html:
function onNotificationAPN(event) {
console.log(event);
if (event.alert) {
$("#app-status-ul").append('<li>push-notification: ' + event.alert + '</li>');
// showing an alert also requires the org.apache.cordova.dialogs plugin
navigator.notification.alert(event.alert);
}
if (event.sound) {
// playing a sound also requires the org.apache.cordova.media plugin
var snd = new Media(event.sound);
snd.play();
}
if (event.badge) {
pushNotification.setApplicationIconBadgeNumber(successHandler, event.badge);
}
}
The console output for event is:
{"event":"message","payload":{"aps":{"alert":"My first push notification!","sound":"default"}},"foreground":true}
When the App is in the foreground the function onNotificationAPN(event) doesn't fire. "event" appears to be returned in or is converted to JSON format.
The IOS registration line is:
pushNotification.register(tokenHandler, errorHandler, {"badge":"true","sound":"true","alert":"true","ecb":"onNotificationAPN"});
How can I modify the code to decode the JSON format and display the alert, play sound, set the badge when the application is in the foreground. There must also be some documentation about the formats that the callback can take and the various options. Otherwise, seems to be working.
After a little playing around I guess that the callback "event" is actually already a JSON object:
console.log(e.event);
console.log(e.payload.aps.alert);
console.log(e.payload.aps.sound);
console.log(e.foreground);
prints out message, My first push notification!, default and true in the log.

how to handle iOS notification callback on phonegap cordova?

I don't know if the title say it properly but..
I have a cordova 1.9 app with push notifications using the PushNotification Plugin and UrbanAirship. Everything works fine.
Now I'd like to open a particular page of my app when I lauch/resume my app from a notification.
Is that possible using Javascript ?
I'm totally lost when reading objective-c.
Notifications causes problem to understand JSON structure.
It is not:
if(notifications.length > 0){
But:
if(notifications.notifications.length > 0){
Array is on: notifications.notifications[] structure.
I am not sure how you are trying to load the page but the simplest way would be to call for the pending notifications as it is in javascript and then use window.location.href to load the require page.
I am using this procedure to perform certain task when I have pending notification at application start:
function registerAirship() {
console.log("ready to register for airship");
window.plugins.pushNotification.registerDevice({alert:true, badge:true, sound:true},function(status) {
if (status.deviceToken) {
window.token = status.deviceToken;
if (status) {
registerUAPush(token, "https://go.urbanairship.com/", key, key1, function(){
window.plugins.pushNotification.getPendingNotifications(function(notifications) {
if(notifications.length > 0){
var note = notifications[0];
if(note.applicationLaunchNotification == "1"){
// use the note.aps and redirect to required page
}
}
});
});
} else {
alert("Registration Error: " + status);
}
}
});
}
I was in your position a few days ago. I decided it was easiest to hack objective-c.
So.
1) I found the function that handled my push notification (AppDelegate.m) and called a js function after objective-c had launched execution for handling the notification. After that line, I did this:
[viewController.webView stringByEvaluatingJavaScriptFromString:#"opensometab()"];
2) In the root of my web app application I added this to the pushnotification.js file (you should be able to put it anywhere but I wanted it here).
** My JS function was to activate a tab within the Viewport so yours may be different.
function opensometab(){
var tabPanel = Ext.Viewport.down('tabpanelname');
tabPanel.setActiveItem(3); //index number 3
}

Resources