arnesson / cordova-plugin-firebase

Cordova plugin for Google Firebase
http://arnesson.github.io/cordova-plugin-firebase
MIT License
1k stars 1.55k forks source link

window.FirebasePlugin.grantPermission(); not prompting on ios #85

Closed aaronorosen closed 7 years ago

aaronorosen commented 7 years ago

I'm not getting prompted for notifications permissions when this method is called. Any ideas? why not. I'm testing on the actual device.

window.FirebasePlugin.getToken(function(token) { alert(token) }); <-- this is working though.

code:

document.addEventListener("deviceready", init, false); function init() { window.FirebasePlugin.grantPermission(); window.FirebasePlugin.getToken(function(token) { console.log(token); }); }

I have the GoogleService-Info.plist in platforms/ios//Resources

any ideas?

achuinard commented 7 years ago

I believe grantPermission has been failing for me recently too, users aren't getting asked to approve pushes.

On Nov 1, 2016 5:31 PM, "Aaron Rosen" notifications@github.com wrote:

I'm not getting prompted for notifications permissions when this method is called. Any ideas? why not. I'm testing on the actual device.

window.FirebasePlugin.getToken(function(token) { alert(token) }); <-- this is working though.

code:

document.addEventListener("deviceready", init, false); function init() { window.FirebasePlugin.grantPermission(); window.FirebasePlugin.getToken(function(token) { console.log(token); }); }

I have the GoogleService-Info.plist in platforms/ios//Resources

any ideas?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/arnesson/cordova-plugin-firebase/issues/85, or mute the thread https://github.com/notifications/unsubscribe-auth/AAcqj20-3SX01e3yoyJQYQxsRvrQhU6qks5q573OgaJpZM4KmqOb .

robertarnesson commented 7 years ago

do you get to deviceready at all? in the code you pasted init is undefined when you bind it

aaronorosen commented 7 years ago

sorry that was a typo on my edit pasting example code. Yes init is called.

aaronorosen commented 7 years ago

I even tried the 0.1.17 and 0.1.16 code and it wasn't working there either. I wonder if it's ios10 related?

achuinard commented 7 years ago

I think it stopped working with iOS 10. I've had users who granted it on iOS9, but new iOS10 users aren't being prompted at all.

aaronorosen commented 7 years ago

Looks like like there is some special casing used in grantPermission() here if it's ios 10 - https://github.com/arnesson/cordova-plugin-firebase/blob/master/src/ios/FirebasePlugin.m#L70 I'm not knowledgeable though about apple's api's and object c though :(

achuinard commented 7 years ago

I've been looking at this for a minute, the only thing I could think of is follows. Will need input from @robertarnesson

The FirebasePlugin.m is where grantPermission executes - https://github.com/arnesson/cordova-plugin-firebase/blob/master/src/ios/FirebasePlugin.m

You'll notice there are 2 special lines for iOS 10+ permissions - [[UNUserNotificationCenter currentNotificationCenter] setDelegate:self]; [[FIRMessaging messaging] setRemoteMessageDelegate:self];

However, 'self' is not the AppDelegate, and I think those methods want to be pointed towards the AppDelegate - see https://github.com/firebase/quickstart-ios/blob/master/messaging/FCM/AppDelegate.m

Could this be the reason?

guyromb commented 7 years ago

Any updates on this?

robertarnesson commented 7 years ago

@achuinard yes you might be right about this. i'll attempt some testing...

robertarnesson commented 7 years ago

possibly related to #74. have you tried this with a production certificate?

aaronorosen commented 7 years ago

Maybe that was the issue. I'm able to get this working now on iOS 10+ now.

achuinard commented 7 years ago

@robertarnesson What about pointing to the delegate though? I'm still confused what the solution is here. Do I just need to re-create certificates through iTunes Connect?

hebaothman commented 7 years ago

+1 it is not working on ios 10 so could you please share what's your solution i have uploaded it to test flight but not working too @aaronorosen @robertarnesson

Thanks in advance

achuinard commented 7 years ago

It is working on iOS 10. You have to make sure you are on the latest version of Xcode and are building the app with the iOS 10 SDK.

aaronorosen commented 7 years ago

I think it might have been a combination of getting the latest x-code that made it start working for me. I'm not completely sure though it's working on my end now following the example in readme.

MattDHill commented 7 years ago

I can only get this to work on the first attempt. Meaning, if the user denies remote notifications, I cannot get the prompt to show again. Is there a way to force the prompt to show again at a later time, say, if the user decides to enable notifications later from within the app preferences?

LufoX11 commented 7 years ago

I'm using XCode 8.2 (last one for my OSX version). Did someone make it work? I'm using Ionic 2 BTW.

aaronorosen commented 7 years ago

@MattDHill I don't believe so. In that case the user needs to go into the app settings and manually enable notifications.

eros2187 commented 7 years ago

Using the plugin I'm noticing that if I call the function as well as you see without calling the grantpermission () function the message is sent but I do not see any notification here is the code

`document.addEventListener('deviceready', onDeviceReady, false);

function onDeviceReady() { $('#console').append('START'); setTimeout(getTheToken, 1000); }

function getTheToken() { window.FirebasePlugin.getToken(function(token) { if (token == null) { console.log("null token"); setTimeout(getTheToken, 1000); } else { //window.FirebasePlugin.grantPermission(); $('#console').append('token: ' + token); console.log("I got the token: " + token); } }, function (error) { $('#consoleerr').append('error retrieving token: ' + error); } ); } ` server {"multicast_id":7649446427278374045,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1494347311775201%812d9b5d812d9b5d"}]}

If I lose the grantPermission () function, the server returns me

`{"multicast_id":6314053970229096456,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidApnsCredential"}]} my device is ipad mini 10.3.1

As can be solved?

aaronorosen commented 7 years ago

Here's the code i'm using and it seems to work if helpful:


function setupPush() {
    if(!(isApp())) {
        return;
    }
    window.FirebasePlugin.grantPermission();
    window.FirebasePlugin.getToken(function(token) {
    // Tell backend token 
    }, function(error) {
        console.error(error);
    });
    window.FirebasePlugin.onNotificationOpen(function(notification) {

        show_push_notification(notification);
    }, function(error) {
        console.error(error);
    });
}
eros2187 commented 7 years ago

Thank you thank you but you work with ios which version? Do the notifications arrive? Do we place a demo project so that everyone can try it? what do you think about it?

aaronorosen commented 7 years ago

it seems to work for all versions for me.

eros2187 commented 7 years ago

Does the download file firebase inside the project be placed on www or on platfom / ios? I put them either inside the root of the project where there are all the folders should i just believe it !?