taivo / parse-push-plugin

Push notification plugin for Cordova/Phonegap/ionic on Parse platform
118 stars 102 forks source link

Cause of empty deviceToken for iOS devices #88

Open budda opened 7 years ago

budda commented 7 years ago

Running the same code on Android and iOS 10.x devices -- the deviceToken field doesn't seem to get populated for iOS devices.

The iOS devices never receive any push notifications. The Android devices receive the notification fine.

Lots of talk over the years online -- but what's the definitive cause and solution ?

bal200 commented 7 years ago

I've been looking into the objective C code to try and fix this issue, or at least understand it. In AppDelegate+parsepush.m file, the didRegisterForRemoteNotificationsWithDeviceToken callback outputs a log comment "PN registration successful. Saving device token to installation". But I don't see this when running my app. So the push registration isn't successful.

I then never see a deviceToken appear in the parse console. This is on iOS 10 phone.

Any ideas?

budda commented 7 years ago

To resolve the lack of deviceToken in iOS 10 we solved it by opening the project in XCode (8.2.1), going to the Project -> Capabilities -> Push Notifications and switch it ON.

We had only activated the Push Notification capability in the App ID on developer.apple.com previously.

Funnily enough, this XCode capability doesn't appear to be documented anywhere in relation to the Cordova plugins.

campers commented 7 years ago

I found this commit in the phonegap push plugin which adds the push entitlement. https://github.com/phonegap/phonegap-plugin-push/commit/e6013d49ecf0025be10fb6bb87152ee4025b5df4

It doesn't show up as enabled in XCode but according to this comment it still works. I don't have an iPhone to test on. https://issues.apache.org/jira/browse/CB-11854?focusedCommentId=15770323&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-15770323

There's a cordova issue to fix that https://issues.apache.org/jira/browse/CB-12316

taivo commented 7 years ago

@campers I used the code you pointed me to. I'm temporarily without an apple developer account so just gonna rambo this in so others can help test. @budda , @bal200 can you guys give this a try?

If it works, I will publish the latest on npm as requested in issue #89

budda commented 7 years ago

Ready to test anything this morning! On Sat, 14 Jan 2017 at 09:19, taivo notifications@github.com wrote:

@campers https://github.com/campers I used the code you pointed me to. I'm temporarily without an apple developer account so just gonna rambo this in so others can help test. @budda https://github.com/budda , @bal200 https://github.com/bal200 can you guys give this a try?

If it works, I will publish the latest on npm as requested in issue #89 https://github.com/taivo/parse-push-plugin/issues/89

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/taivo/parse-push-plugin/issues/88#issuecomment-272612552, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGZ4dSZ12ud6As1iMio-KkAIGYqBFynks5rSJMzgaJpZM4LiVKj .

taivo commented 7 years ago

@budda I've already committed the new change, so just install straight from this repo (installation step 1 of the README) and test away! Thank you for your help!

budda commented 7 years ago

I did an $ ionic state reset to re-download all platforms and plugins.

I noted the plugin.xml was up to date with the aps-environment bits. However, no *.entitlements file was generated in the project root. Checking the Project -> Capabilities config showed the Push Notifications option was not enabled.

Manually enabling Push Notifications prompted me to first select a "development team" account (I only have one available in the drop down). So this may be a blocker to the automatic setting up of entitlements?

Just seen a build.json file can help - https://dpogue.ca/articles/cordova-xcode8.html

So right now it is hard to verify if the plugin.xml changes have worked automatically.

taivo commented 7 years ago

@Danlugo mentioned in issue #78 that it can also be a parse caching issue. If that's the case a full uninstall of your app would help

budda commented 7 years ago

Okay i'm up and working with iOS fine now.

build.json also implemented and working for setting the provisioning certs.

However the plugin.xml doesn't appear to be setting the Push Notification capability setting to 'on' if remove and add the ios platform to reset the xcodeproj file i always have to re-open in XCode and manually set the capability again.

GreatSpoon commented 7 years ago

Hello,

I am having the same issue referenced above. I am able to get the device token from the app.js file if I print if after installation but it still remains blank in the installations table. If i manually fill in the device token and user ID, I can send push notifications to that device just fine.

This is happening whether I build the app to an Iphone or install it through TestFlight.

Any Ideas?