【问题标题】:how to send the device token to server in ios6?如何在 ios6 中将设备令牌发送到服务器?
【发布时间】:2012-10-08 09:53:17
【问题描述】:

我想在我的应用程序中将设备令牌发送到服务器。我正在使用以下方法来检索设备令牌。

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
     NSLog(@"deviceToken: %@", deviceToken);
}

但在 ios6 中不起作用。怎么会这样?

【问题讨论】:

    标签: iphone ios6 devicetoken


    【解决方案1】:

    这行你写了吗

    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
     (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
    

    在这个函数内部,

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    

    如果你这样做了,它应该可以在 iOS 6 中工作。

    【讨论】:

      【解决方案2】:

      如果您使用 Urbanariship,则需要先清理 deviceToken,然后再通过 NSURLConnection PUT 将其发送回 urbanairship 服务器。

      NSString *deviceToken = [[_deviceToken description] stringByReplacingOccurrencesOfString: @"<" withString: @""];
          deviceToken = [deviceToken stringByReplacingOccurrencesOfString: @">" withString: @""] ;
          deviceToken = [deviceToken stringByReplacingOccurrencesOfString: @" " withString: @""];
      

      否则,您可以使用 NSURequest/NSURLConnection 发送

      希望这对您有所帮助。或者如果您也想要请求和连接的代码,请告诉我们。

      【讨论】:

      • /*[[UAirship shared] registerDeviceToken:deviceToken]*/ 注册设备令牌在 libUairship-1.3.0 中已弃用... 我该怎么办?知道的请帮忙。
      猜你喜欢
      • 2011-11-20
      • 1970-01-01
      • 1970-01-01
      • 2020-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-08
      • 1970-01-01
      相关资源
      最近更新 更多