推送通知中的设备令牌要求

Device Token requirement in push notification

我实际上在我的游戏中实现了推送通知服务,但我心里有一些问题想解决。

完全在我们的自定义服务器上完成实施,因此没有使用任何第三方服务帮助。为此,我使用了核心 Unity 推送通知代码。

NotificationServices.deviceToken

注册完成后,我需要添加deviceToken到网络服务器。为什么我需要这样做?我无法理解这个概念。

如果我添加 SystemInfo.deviceUniqueIdentifier 那么它将无法发送任何推送通知。它只能与 deviceToken 一起使用。

请与此分享您的建议。

推送通知只能在设备令牌上工作,您必须获取它并将其存储在服务器上。

我们在服务器上存储了设备令牌,以便服务器向所有用户发送通知。 如果我们不保存设备令牌,那么服务器如何发送通知以及在哪里发送通知(设备令牌是每个设备的唯一 ID)。

在app delegate中你必须用这个方法获取它

-(void)application:(UIApplication *)app
                   didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken 
 {

       const unsigned *tokenBytes = [deviceToken bytes];
       NSString *hexToken = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",
                      ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),
                      ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),
                      ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];

     [[NSUserDefaults standardUserDefaults] setObject:hexToken forKey:@"DeviceTokenValue"];// Save your device token for use
     [self saveDeviceToken:hexToken];//Send your device token to the server with API

  }