嗯,要開始我想確保如果您在應用程序啓動時在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 and Mobile Guru或Austin Web Design
沒有辦法,您需要將它發送到將發送通知的服務器。服務器將令牌存儲在數據庫中,並用它將通知發送到註冊的設備。 –