我们向我们的应用程序添加了推送通知,但我们需要帮助将设备 token 发送到我们的数据库。截至目前,我们已经设置了数据库,所以我们所要做的就是从 NSLog 中获取设备 token 并将其放在数据库 URL 的末尾:http://www8.XXXXXXX.net/XXXXX_push/register.cfm ?token=TOKEN_HERE 如果我们使用 Safari,我们只需在 URL 栏中输入最后的真实 token ,然后按回车键,数据库就会收到 token 。 我们觉得我们需要将代码放在应用程序中:
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
但我们只是不知道要使用什么代码...因为我们对此真的很陌生。
有人可以告诉我们使用什么代码来发送我们制作的 NSURL 吗?
附言这是我们目前所拥有的:
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSString *str = [NSString
stringWithFormat:@"Device Token=%@",deviceToken];
NSLog(str);
NSString *fullURL = [NSString stringWithFormat:@"http://www8.xxxxxxxxx.net/xxxxx_push/register.cfm?token=%@",str];
NSURL *tokenURL = [NSURL URLWithString:fullURL];
最佳答案
didRegisterForRemoteNotificationsWithDeviceToken 是您正在做的事情的正确位置。
我使用从 urbanairship.com 借用的这段代码来清理 deviceToken,然后通过 NSURLConnection PUT 将其发送回 urbanairship 服务器。
NSString *deviceToken = [[_deviceToken description] stringByReplacingOccurrencesOfString: @"<" withString: @""];
deviceToken = [deviceToken stringByReplacingOccurrencesOfString: @">" withString: @""] ;
deviceToken = [deviceToken stringByReplacingOccurrencesOfString: @" " withString: @""];
关于iphone - 需要帮助将带有设备 token 的 URL 从我们的 iPhone 应用程序发送到我们的数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5021642/