简体   繁体   中英

Another way to get push device token ios?

I wonder, is there another way to get the push device token without the delegate method:

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(nonnull NSData *)deviceToken

because I used OneSignal, and they don't need to conform that method to get the device token.

You can get the push token for OneSignal SDK like this:

 OneSignal.promptForPushNotifications(userResponse: { accepted in
  print("User accepted notifications: \(accepted)")
            
  if let deviceState = OneSignal.getDeviceState() {
    let userId = deviceState.userId
    let pushToken = deviceState.pushToken
    let subscribed = deviceState.isSubscribed
    print("pushToken ====> \(pushToken)") //Here you can get the token
  }
 })

Keep coding........... :)

OneSignal API states IdsAvailable is the method you would use:

[OneSignal IdsAvailable:^(NSString* userId, NSString* pushToken) {
    NSLog(@"UserId:%@", userId);
    if (pushToken != nil)
        NSLog(@"pushToken:%@", pushToken);
}];

Is the method to get the token; mentioned here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM