简体   繁体   English

iPhone的推送通知-接受的方法

[英]Push Notifications for iPhone - accepted methodolgy

I'm looking at the designing and developing a service for Push notifications, and am trying to understand the order of processing in the Apple App when it comes to Registering for Push Notifications and storage of the Token. 我正在研究设计和开发用于Push通知的服务,并试图了解Apple App在注册Push通知和令牌存储方面的处理顺序。 What I'm developing currently is a service that allows subscription to individual changes that happen to particular processing on our server. 我目前正在开发的是一项服务,该服务允许订阅发生在我们服务器上特定处理过程中的各个更改。 When they happen, the phone user may receive a message of type “A”, “B”, or “C”. 发生这种情况时,电话用户可能会收到“ A”,“ B”或“ C”类型的消息。 The phone user has to “subscribe” to each of these types individually if they want them. 电话用户如果需要,必须分别“订阅”这些类型中的每一个。 Otherwise they can ignore it and not subscribe. 否则,他们可以忽略它而不订阅。

So User Fred, on Phone #4, starts our App, logs in, and then has the ability to turn on or off subscriptions to events that are sent as Push Notifications. 因此,电话4上的用户弗雷德启动了我们的应用程序,登录并具有打开或关闭作为推送通知发送的事件的订阅的功能。

So I need to tie details from Fred's login, to Phone #4's device Token, with particular subscriptions. 因此,我需要将Fred的登录信息与特定订阅的电话4的设备令牌绑定在一起。

So my particularly important questions are. 因此,我特别重要的问题是。

When the Phone connects to the APNS server to get its device token, is this automatic on app start? 当电话连接到APNS服务器以获取其设备令牌时,此功能是否在应用程序启动时自动启动? Or can this be initiated at a later step? 还是可以在以后的步骤中启动? Ie, after going through a loging screen on our app. 即,通过我们的应用程序的登录屏幕后。

Can we (are we allowed to) store the device token on the phone in the App's data store?. 我们可以(允许)将设备令牌存储在手机的应用程序数据存储区中吗? Or, should the App be connecting to the APNS server every time the app is run? 还是应该在每次运行该应用程序时将其连接到APNS服务器?

How does the App know if it as already called the APNS server and retrieved a token, or as above, should it call the APNS server time the app is run? 应用程序如何知道它是否已经调用了APNS服务器并检索了令牌,或者如上所述,它应该在应用程序运行时调用APNS服务器吗?

Can we (are we allowed to) store the token in the App's memory as it runs, so we can properly subscribe and unsubscribe for particular messages? 我们可以(允许)在应用程序运行时将令牌存储在应用程序的内存中,以便我们可以正确地订阅和取消订阅特定消息吗?

We need also to be able to list all the subscriptions that a particular user may have across all their devices so the user can remove old devices (if they change phones). 我们还需要能够列出特定用户可能在其所有设备上拥有的所有订阅,以便该用户可以删除旧设备(如果他们更换电话)。 Or can we rely upon data back from calls to the APNS – when we attempt to push a notification - to inform us that a device token is no longer valid? 或者,当我们尝试推送通知时,我们可以依靠从APNS调用返回的数据来通知我们设备令牌不再有效吗?

Or is there some better way of tying this all together? 还是有一些更好的方法将这些结合在一起?

When the Phone connects to the APNS server to get its device token, is this automatic on app start? 当电话连接到APNS服务器以获取其设备令牌时,此功能是否在应用程序启动时自动启动? Or can this be initiated at a later step? 还是可以在以后的步骤中启动? Ie, after logging into our app. 即,登录到我们的应用程序后。

After the app has started, the app gets the token by calling registerForRemoteNotificationTypes. 应用程序启动后,该应用程序通过调用registerForRemoteNotificationTypes获得令牌。 This will prompt the user for permission, and call a callback with the device token if permission is granted. 这将提示用户许可,如果授予许可,则使用设备令牌调用回调。

Can we (are we allowed to) store the device token on the phone in the Apps data store?. 我们可以(允许)将设备令牌存储在手机上的Apps数据存储区中吗? Or, should the App be connecting to the APNS server every time the app is run? 还是应该在每次运行该应用程序时将其连接到APNS服务器?

You'll need to build an APN provider , which is a web server that calls apple to send the pushes. 您需要构建一个APN提供程序 ,这是一个网络服务器,调用apple来发送推送。 The thing to do with the token is post it to your server that uses the APN provider. 与令牌有关的事情是将其发布到使用APN提供程序的服务器中。 The app doesn't connect to APNS, your provider does, and it does it when it has pushes to send. 该应用程序未连接到APNS,您的提供商已连接,并且在推送发送时便已连接。

Can we (are we allowed to) store the token in the App's memory as it runs, so we can properly subscribe and unsubscribe for particular messages? 我们可以(允许)在应用程序运行时将令牌存储在应用程序的内存中,以便我们可以正确地订阅和取消订阅特定消息吗?

You can keep the token on the client, but you don't really need to. 您可以将令牌保留在客户端上,但实际上并不需要。 It's your web service that calls APN, so it needs to be kept aware of your users' subscription prefs. 是您的Web服务调用了APN,因此需要时刻注意用户的订阅偏好。

We need also to be able to list all the subscriptions that a particular user may have across all their devices so the user can remove old devices (if they change phones). 我们还需要能够列出特定用户可能在其所有设备上拥有的所有订阅,以便该用户可以删除旧设备(如果他们更换电话)。 Or can we rely upon data back from calls to the APNS – when we attempt to push a notification - to inform us that a device token is no longer valid? 或者,当我们尝试推送通知时,我们可以依靠从APNS调用返回的数据来通知我们设备令牌不再有效吗?

APN also provides a feedback service that you call in batch which returns the device tokens that are no longer valid. APN还提供您批量调用的反馈服务,该服务将返回不再有效的设备令牌。 Not only can you use this service, but you must . 您不仅可以使用此服务,还必须使用 Apple will get mad at apps that repeatedly send to no longer valid devices. 苹果会对反复发送到不再有效的设备的应用感到生气。

Or is there some better way of tying this all together? 还是有一些更好的方法将这些结合在一起?

Yes! 是! Parse.com provides a nice wrapper on the client code, does the provider and feedback service, abstracts the idea of single devices to the idea of a "channel" which sounds like just what you need for multiple notification types A, B, C, provides a super-easy step by step setup, and loads of other useful cloud services for iOS. Parse.com为客户端代码提供了一个很好的包装器,提供了提供程序和反馈服务,将单个设备的概念抽象为“通道”的概念,这听起来就像您需要多种通知类型A,B,C,提供了一个非常简单的逐步设置,并为iOS加载了其他有用的云服务。 (I'm not affiliated, but a big fan). (我没有隶属关系,但非常支持)。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM