Push notification with OneSignal: What means “No P

2019-06-15 12:52发布

问题:

I'm using OneSignal for push notifications.

In the subscribed list some devices/users are marked with No (No Push Token). Explanation says: This user has no push token and cannot be targeted.

That occurs for iOS devices as well as for Android devices.

What does it mean? Why does it happen? How to change it?

回答1:

This means OneSignal did not get a pushToken from the device however the device was able to register with your OneSignal account. On iOS the pushToken is known as the device token, on Android this is the Google registration id.

Depending on the OneSignal SDK you're using there is a setLogLevel function that can be called before you call OneSignal init to add additional logging. This will be printed in the Xcode log for iOS or adb logcat for Android. Also make sure you are using the last OneSignal SDK.

You can also contact OneSignal through the help bubble on the bottom of the page while logged in and they can check your account to help diagnose the issue.



回答2:

Could you check if the "Push Notifications" capability is turned on? If it is not, turn it on and see if it works, otherwise keep reading.

Make sure you're running the latest version of the OneSignal SDK (2.1.14) as this version should have resolved the issue. Next, try the following fixes:

Fix 1

From the navigation panel, select your top blue project. Then select your target and navigate to the Build Settings. Search for other linker flags and add the following entry: -ObjC

Do a project clean and run again, see if it works.

Fix 2

In your bridging header (if you have one), or on any header file that is visible to your App Delegate, create an extension for OneSignal class in which you define the following interface method:

+ (void)didRegisterForRemoteNotifications:(UIApplication*)app deviceToken:(NSData*)inDeviceToken;

Next, override the didRegisterForRemoteNotifications delegate method in your app delegate and call the above method on OneSignal and pass both parameters to the SDK.



回答3:

Note that there was a pretty significant flaw in the OneSignal SDK when used in XCode 8 up to version 2.1.10 that resulted in these No push token registrations for iOS devices when including the package using Cocoapods (the recommended approach). Make sure you update your pod.

See the release notes for 2.1.11:

Fixed a 'No Push Token' issue in 2.1.10 that would happen when OneSignal was downloaded through CocoaPods and included other pods that used the -ObjC flag.



回答4:

Make sure that your Xcode project has "Push Notifications" and "Remote notifications" enabled.



回答5:

As other answer mentioned, there is a bug in 2.1.10 for CocoaPods setup. So I changed

from

pod 'OneSignal' ## points to 2.1.10

to

pod 'OneSignal', :git => 'https://github.com/OneSignal/OneSignal-iOS-SDK.git', :branch => 'master'