我正在为我的应用使用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 :(得分:1)
希望它有所帮助。
答案 1 :(得分:0)
应用程序应在每次启动时重新注册推送通知,作为Apple推荐的最佳做法。 (见Apple Local and Push Notifications Programming Guide)
如何在服务器端域中存储设备ID取决于您。一个例子是具有表示设备最后注册时间的列。如果它是新设备ID,您将添加一行;如果设备ID已存在,则更新具有新时间戳的行。