简体   繁体   English

如何在iPhone中以不同方式使用设备令牌?

[英]How to use device tokens in different ways in iphone?

In my application i am going to use pushNotification. 在我的应用程序中,我将使用pushNotification。 So in that case how can i use device tokens in different ways? 因此,在那种情况下,我如何以不同方式使用设备令牌?

Let me elaborate more on this side. 让我在这方面详细说明。

Whenever i run my application at that time Device token will be generated,if i go for running the application again and again in the same device than it will generate the same device token or not? 每当我那时运行我的应用程序时,都会生成设备令牌,如果我在同一设备中一次又一次地运行该应用程序,会否生成相同的设备令牌?

if it will generate the different Device tokens than as per the Apple Documentation how is it Handling at the server side.? 如果它将生成与Apple文档中所描述的设备令牌不同的设备令牌,那么它将如何在服务器端进行处理? what is exactly needed to send from client side (ie Device token or other parameters) to the server side and which type of scenario is having at the server side for the same? 从客户端(即设备令牌或其他参数)发送到服务器端到底需要什么?对于相同的情况,服务器端具有哪种类型的方案?

if anybody having any solution or any code snippet or any useful link,which would be appreciated. 如果有人有任何解决方案或代码段或任何有用的链接,将不胜感激。

Here is an example, not necessarily working code: 这是一个示例,不一定是工作代码:

- (void)sendProviderDeviceToken:(NSString *)tokenString {
    NSString *udid = [[UIDevice currentDevice] uniqueIdentifier];

    NSString *bundleID = [[NSBundle mainBundle] bundleIdentifier];
    UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

    NSString *data = [NSString stringWithFormat:@"udid=%@&token=%@&id=%@&type=%i", udid, tokenString, bundleID, type];
    NSString *escapedData = [[data description] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    NSString *httpRequestURLString = [NSString stringWithFormat:@"http://%@/RegisterDevice.cgi?%@", kRegistrationURI, escapedData];
    NSURL    *httpRequestURL       = [NSURL URLWithString:httpRequestURLString];
}

Mishal, per your comment on CocoaFu's answer Mishal,根据您对CocoaFu答案的评论

I mean whenever i launch my application at that time it will generate the different tokens for that device or not? 我的意思是,每当我启动我的应用程序时,它将为该设备生成不同的令牌吗? And if it generates the different tokens than how to handle it in the proper way? 如果它生成的令牌与如何正确处理令牌的方式不同?

This paragraph in the iOS doc is helpful in understanding when device tokens can change on a user's device, and why you fire it every time the app launches: iOS文档中的这一段有助于理解何时可以在用户的​​设备上更改设备令牌,以及为何每次启动应用程序时都将其触发:

By requesting the device token and passing it to the provider every time your application launches, you help to ensure that the provider has the current token for the device. 通过在每次启动应用程序时请求设备令牌并将其传递给提供程序,可以帮助确保提供程序具有设备的当前令牌。 If a user restores a backup to a device other than the one that the backup was created for (for example, the user migrates data to a new device), he or she must launch the application at least once for it to receive notifications again. 如果用户将备份还原到不是为其创建备份的设备上(例如,用户将数据迁移到新设备),则他或她必须至少启动一次该应用程序才能使其再次接收通知。 If the user restores backup data to a new device or reinstalls the operating system, the device token changes. 如果用户将备份数据还原到新设备或重新安装操作系统,则设备令牌会更改。 Moreover, never cache a device token and give that to your provider; 此外,切勿缓存设备令牌并将其提供给您的提供商。 always get the token from the system whenever you need it. 始终在需要时从系统获取令牌。 If your application has previously registered, calling registerForRemoteNotificationTypes: results in iOS passing the device token to the delegate immediately without incurring additional overhead. 如果您的应用程序先前已注册,则调用registerForRemoteNotificationTypes:将导致iOS立即将设备令牌传递给委托,而不会产生额外的开销。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在iPhone设备上使用AVAudioSessionCategoryMultiRoute? - How to use AVAudioSessionCategoryMultiRoute on iPhone device? 查找特定半径范围内的iPhone设备/设备令牌: - Find iPhone devices/device tokens in specific radius :- 如何设置背景图像以查看不同的iPhone设备 - How to set backgroundimage for view for different iPhone Device 如何在iPhone设备上使用Time Profiler仪器 - How to use Time Profiler Instrument with iPhone Device 使用iPhone和Android进行套接字连接的不同方法? - Different ways to make a Socket Connection with iPhone and Android? iPhone - 存储数据的不同方式,优点和缺点 - iPhone - different ways to store data, advantages and disadvantages 沙盒与生产中的iPhone APNS设备令牌 - iPhone APNS Device Tokens in sandbox vs. production 如何检测破解的iPhone应用程序和越狱设备(不同的方法) - How to detect a cracked iPhone App and a jailbroken device (different methods) iPhone View Animation在Simulator上播放2种方式,在Device上仅播放1种方式 - iPhone View Animation plays 2 ways on Simulator, only 1 way on Device 如何为 iPhone 设备使用不同的字体? - How to use different font for iPhone devices?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM