xcode 使用推送通知时如何处理多个设备?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1642182/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:55:49  来源:igfitidea点击:

how to handle multiple devices when using Push Notification?

objective-cxcodeiphone-sdk-3.0push-notification

提问by Rahul Vyas

I am developing an application in which I want to use push notification service. I have a server, now I want to know that

我正在开发一个应用程序,我想在其中使用推送通知服务。我有一个服务器,现在我想知道

  • How do I handle multiple devices?

  • Is there a unique device id/name for every iphone?

  • Suppose I want to delete request for a specific device token, so how do I handle multiple users?

  • Is there a way I can generate unique name for every device through application?

  • 如何处理多个设备?

  • 每部 iphone 都有唯一的设备 ID/名称吗?

  • 假设我想删除对特定设备令牌的请求,那么如何处理多个用户?

  • 有没有办法通过应用程序为每个设备生成唯一的名称?

回答by Louis Gerbarg

You should really read the APNS documentation, this is all explained in depth there.

您应该真正阅读 APNS文档,那里有详细解释。

The short answer is that when you launch an app on the phone it requests a push notification key from the OS. You then take that key and send it back to your server. Your server uses that key when it sends a push via Apple's servers to indicate the devices to send the push out to.

简短的回答是,当您在手机上启动应用程序时,它会向操作系统请求推送通知密钥。然后您获取该密钥并将其发送回您的服务器。您的服务器在通过 Apple 的服务器发送推送时使用该密钥来指示要将推送发送到的设备。

The service just gives you a token. If you want accounts or device names you need to come up with them and store them with the credentials on your server.

该服务只是给你一个令牌。如果您需要帐户或设备名称,您需要想出它们并将它们与凭据一起存储在您的服务器上。

You handle multiple users by same way you handle single users, you send message with the appropriate key to the service.

您可以通过与处理单个用户相同的方式来处理多个用户,向服务发送带有适当密钥的消息。

As for deleting a request, you can't. It is like a text message, there may be some latency before hits the device, but the moment you commit the push it could be delivered instantly.

至于删除请求,你不能。这就像一条短信,在到达设备之前可能会有一些延迟,但是当您提交推送时,它可以立即交付。