我需要获取我的iPhone上的设备令牌来测试推送通知。 在我的iPhone上,我已经同意通知推送权限。我尝试删除并重新安装应用程序,但没有。我尝试在didRegisterForRemoteNotificationsWithDeviceToken
方法中加入一个缺点,但没有任何结果。获取设备令牌推送通知第二次在iPhone上
有什么建议吗?
这是我的代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
/**** PUSH NOTIFY ****/
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSMutableString *str = [[NSMutableString alloc] initWithFormat:@"http://www.mysite.com/storeToken.php?task=register&token=%@", [self stringWithDeviceToken:deviceToken]];
//NSLog(@"%@",str);
NSUserDefaults *pref = [NSUserDefaults standardUserDefaults];
[pref setObject:[self stringWithDeviceToken:deviceToken] forKey:@"token"];
[pref synchronize];
NSURL *url = [NSURL URLWithString:str];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request startSynchronous];
[str release];
}
- (NSString*)stringWithDeviceToken:(NSData*)deviceToken {
const char* data = [deviceToken bytes];
NSMutableString* token = [NSMutableString string];
for (int i = 0; i < [deviceToken length]; i++) {
[token appendFormat:@"%02.2hhX", data[i]];
}
return [[token copy] autorelease];
}
这是错误,它打印:
Error: Error Domain=NSCocoaErrorDomain Code=3000 "nessuna stringa di autorizzazione 'aps-environment' valida trovata per l'applicazione" UserInfo=0x296e80 {NSLocalizedDescription=nessuna stringa di autorizzazione 'aps-environment' valida trovata per l'applicazione}
你的推送通知设置启用配置文件? – 2012-03-16 11:24:30
是的,它启用。我不明白,因为调试不输入在didRegisterForRemoteNotificationsWithDeviceToken方法。 – Dany 2012-03-16 11:26:40