嗯,要开始我想确保如果您在应用程序启动时在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
没有办法,您需要将它发送到将发送通知的服务器。服务器将令牌存储在数据库中,并用它将通知发送到注册的设备。 –