我想在我的应用程序中将设备令牌发送到服务器。我正在使用以下方法来检索设备令牌。
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(@"deviceToken: %@", deviceToken);
}
但不适用于ios6。怎么能做到这一点?
我想在我的应用程序中将设备令牌发送到服务器。我正在使用以下方法来检索设备令牌。
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(@"deviceToken: %@", deviceToken);
}
但不适用于ios6。怎么能做到这一点?
你写过这一行吗
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
在这个函数里面,
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
如果你这样做了,它应该在 iOS 6 中工作。
如果您使用的是 Urbanariship,则需要先清理 deviceToken,然后再通过 NSURLConnection PUT 将其发送回 urbanairship 服务器。
NSString *deviceToken = [[_deviceToken description] stringByReplacingOccurrencesOfString: @"<" withString: @""];
deviceToken = [deviceToken stringByReplacingOccurrencesOfString: @">" withString: @""] ;
deviceToken = [deviceToken stringByReplacingOccurrencesOfString: @" " withString: @""];
否则,您可以使用 NSURequest/NSURLConnection 发送
希望这会帮助你。或者如果您还想要请求和连接的代码,请告诉我们。