2011-01-05 69 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"

希望它能幫助。