registerForRemoteNotificationTypes
まず、アプリの起動時に次のコマンドを実行していることを確認したいと思います。AppDelegateに追加できるものは次のとおりです
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
// Send the deviceToken to server right HERE!!! (the code for this is below)
NSLog(@"Inform the server of this device token: %@", deviceToken);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
// Place your code for what to do when the ios device receives notification
NSLog(@"The user info: %@", userInfo);
}
- (void)application:(UIApplication *) didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
// Place your code for what to do when the registration fails
NSLog(@"Registration Error: %@", err);
}
プッシュ通知用のデバイストークンの登録について言及する場合は、プッシュ通知を送信しているサーバーにdeviceTokenを送信し、サーバーにプッシュ用のデータベースに保存させる必要があります。これをサーバーに送信する方法の例を次に示します。
NSString *host = @"yourhost";
NSString *URLString = @"/register.php?id=";
URLString = [URLString stringByAppendingString:id];
URLString = [URLString stringByAppendingString:@"&devicetoken="];
NSString *dt = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
dt = [dt stringByReplacingOccurrencesOfString:@" " withString:@""];
URLString = [URLString stringByAppendingString:dt];
URLString = [URLString stringByAppendingString:@"&amp;amp;amp;amp;devicename="];
URLString = [URLString stringByAppendingString:[[UIDevice alloc] name]];
NSURL *url = [[NSURL alloc] initWithScheme:@"http" host:host path:URLString];
NSLog(@"FullURL=%@", url);
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
もう助けが必要な場合は、喜んでお手伝いします。Austin Web andMobileGuruまたはAustinWebDesignのいずれかのWebサイトで私に連絡してください