另一种获取推送设备令牌ios的方法?

时间:2017-03-03 04:27:17

标签: ios apple-push-notifications push onesignal devicetoken

我想知道,是否有其他方法可以在没有委托方法- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(nonnull NSData *)deviceToken的情况下获取推送设备令牌 因为我使用了OneSignal,他们不需要使用该方法来获取设备令牌。

2 个答案:

答案 0 :(得分:2)

OneSignal API状态 IdsAvailable 是您要使用的方法:

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

是获取令牌的方法;提到here

答案 1 :(得分:2)

您可以像这样获取 OneSignal SDK 的推送令牌

 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
  }
 })

继续编码........... :)