2011-01-05 65 views
0

我正在使用PushNotification为我的应用程序。它似乎每次加载应用程序时都会生成设备令牌。所以在我的服务器中,我有许多重复的设备令牌。iPhone PushNotification注册多次

我需要将它添加到数据库之前,检查设备令牌还是我做一些事情错在应用程序执行?

下面是我使用的代码段。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 

// launchOptions has the incoming notification if we're being launched after the user tapped "view" 
NSLog(@"didFinishLaunchingWithOptions:%@", launchOptions); 

// [self.viewController handleDidReceiveRemoteNotification:userInfo]; 


// other setup tasks here.... 
    [[UIApplication sharedApplication] 
    registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | 
      UIRemoteNotificationTypeSound | 
      UIRemoteNotificationTypeAlert)]; 

    // [self updateWithRemoteData]; // freshen your app! 

// RESET THE BADGE COUNT 
    application.applicationIconBadgeNumber = 0; 

    // ... 
// call the original applicationDidFinishLaunching method to handle the basic view setup tasks 
[self applicationDidFinishLaunching:application]; 

return YES; 
} 



- (void)application:(UIApplication *)app 
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken { 
    [self sendDeviceTokenToRemote:devToken]; // send the token to your server 
} 

有人可以帮忙吗?如何将独特的设备令牌存储在我的服务器中?

感谢, Nikil

+0

感谢yar对我来说非常有用。 – nambi 2012-01-09 10:37:18

回答

0

应用程序应该在每次启动时由苹果推荐的最佳实践推送通知重新注册。 (见Apple Local and Push Notifications Programming Guide

你的设备ID如何存储在服务器端域

是你。一个例子是有一列表示设备注册的最后一次。如果设备ID是新设备ID,则会添加一行;如果设备ID已存在,则使用新时间戳更新行。

1
  1. 在大多数情况下,分配给每个设备的APN令牌是唯一且恒定的。您可以将其视为另一种UDID。所以一旦设备注册到服务器的数据库中,您就不必再次注册了。
  2. (这是棘手的部分)。然而,根据苹果的文档,APN的令牌可以改变,比方说,如果该设备已经更新到更高版本的操作系统,或者有一些它的硬件与一个新的来代替。但是,这并不经常发生。
  3. 作为将在您的应用程序存储该APN的令牌,并在你的服务器上,检查这个帖子,iPhone pushNotification DeviceToken - How to "decrypt"

希望它能帮助。