链接用户帐户设备令牌推送通知 [英] Linking user account to device token for push notifications

查看:267
本文介绍了链接用户帐户设备令牌推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序建立与API服务器和每个用户通过电子邮件或Facebook的时候,他们下载的应用程序创建一个帐户。该信息全部存储在后端。我想启用推送通知,让自己特定的用户。我知道需要与APNS服务器等等。我的问题是连接与用户帐户的设备令牌,所以我可以根据从我的服务器上的逻辑发出正确的用户将正确的信息在后端做了什么。

I have an app set up with an API server and each user creates an account either by email or facebook when they download the app. That information is all stored in the back end. I want to enable push notifications so that they are user specific. I know what needs to be done on the back end with APNS server etc. My question is linking the Device Token with a user account so I can send the right user the right information based on logic from my servers.

我知道,我把这个code在的applicationDidFinishLaunching

I know that I place this code in the applicationDidFinishLaunching:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];

    // Let the device know we want to receive push notifications
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
        (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

    return YES;
}

然后我抓住的设备ID从这里:

And then I grab the device ID from here:

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
    NSLog(@"My token is: %@", deviceToken);
}

- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
    NSLog(@"Failed to get token, error: %@", error);
}

我在想,当我在用户的迹象可以只发送装置凭证到我的服务器,并将其与用户相关联是否正确?我可以再补充一个属性的API调用来处理,我只是想确保是内联与苹果的预期行为。然后,当用户注销,我只想从自己的用户名清除设备令牌,这样如果另一个用户登录同一台设备上我不会有重复的令牌。

Am I correct in thinking that when the user signs in I can just send the device token to my server and associate it with that user? I can just add an attribute to the API call to handle that, I just want to make sure that is inline with Apple's expected practices. Then when a user logs out I would just clear the Device Token from their username so that if another user logs in on the same device I wouldn't have a duplicate token.

推荐答案

这正是你应该做的。在 didRegisterForRemoteNotificationsWithDeviceToken 你可以存储设备令牌本地,然后,当用户登录时,您可以发送用户标识到服务器的设备令牌。

That's exactly what you should do. In didRegisterForRemoteNotificationsWithDeviceToken you can store the device token locally, and then, when the user logs-in, you can send the device token with the user identifier to your server.

这篇关于链接用户帐户设备令牌推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆