プッシュ通知をテストするには、iPhone でデバイス トークンを取得する必要があります。私の iPhone では、プッシュ許可を通知することに既に同意していました。アプリを削除して再インストールしようとしましたが、何もしません。メソッドにブレークポイントを入れようとしましたdidRegisterForRemoteNotificationsWithDeviceToken
が、何もありません。
なにか提案を?
これは私のコードです:
- (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}