如何将推送通知发送到特定设备 [英] How to send push notification to specific device

查看:218
本文介绍了如何将推送通知发送到特定设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将这篇文章读到:

Apple推送通知给特定用户

我需要将推送发送到特定设备,但我的问题是登录我的应用程序的用户,由生成的UDID标识,而不是使用已弃用的UIDevice。我看到easyAPNS将这些值存储到MySQL中:

I need to send push to specific devices, but my problem is that users that log into my app, are identified by a generated UDID, not using the deprecated UIDevice. I see that easyAPNS stores this values into the MySQL:

CREATE TABLE `apns_device_history` (
2
  `pid` int(9) unsigned NOT NULL auto_increment,
3
  `appname` varchar(255) NOT NULL,
4
  `appversion` varchar(25) default NULL,
5
  `deviceuid` char(40) NOT NULL,
6
  `devicetoken` char(64) NOT NULL,
7
  `devicename` varchar(255) NOT NULL,
8
  `devicemodel` varchar(100) NOT NULL,
9
  `deviceversion` varchar(25) NOT NULL,

我不知道如何将注册的应用用户链接到此表,以实现向特定用户发送推送。是否可以通过代码用户pid或设备令牌获取?

I don't know how to link registered app users with this table, in order to achieve to send push to specific user. Is it possible to get by code user pid or device token?

非常感谢!

推荐答案

开发任何级别的APNS都是一项艰巨的任务,除非您对服务器端和客户端方面的内容有很多了解。

Developing any level of an APNS can be quite an undertaking unless you have a lot of knowledge into what is involved on both a server side and client side perspective.

需要注意的事项:


  1. 服务器端必须考虑到设备标识符(令牌)如果更新或恢复将在每台设备上发生变化他们的设备 - 甚至是新设备!

  2. 客户端必须考虑必须在App Delegate中实现的委托方法才能正确接受和处理这些推送通知,以及开始发起他们。 (示例如下)。

  3. 如果您没有设置正确的反馈服务,服务器必须再次意识到您可以将推送通知证书列入黑名单。这样做是检查该标识符是否存在,如果没有,则将其从数据库中取出,这样就不会再继续尝试向该用户发送推送通知。

  4. 关于服务器,您可以一次发送一个通知(每个通知之间的时间)或将它们排队到大量并流这些通知。实际上你必须遵循这个或者你可能会被黑名单,并且无法再次向你的用户发送推送通知。

  1. Server side must take into consideration that device identifiers (tokens) will change on each device if they update or restore their device - or even get a new device!
  2. Client side must take into consideration the delegate methods that must be implemented into the App Delegate to properly accept and handle these push notifications, as well as begin initiating them. (examples follow below).
  3. Server again must realize that you can get your push notification certificate black-listed if you don't set up a proper "feedback" service. What this does is check if that identifier exists, and if not then you take it out of your database so you don't continue trying to send push notifications to that user again.
  4. On the server you can either send one notification at a time (with time in between each individual one) or queue them up into a mass amount and "stream" these notifications. Really you MUST follow this or again you can be black-listed and won't be able to send push notifications to your users again.

在我们开始创建任何类型的推送通知服务器之前,确实需要了解这4点。

Those 4 points really need to be understood before we begin any undertaking of creating any sort of push notification server.

id (int)
token (int - 32 length)
dateChanged (dateTime)

三个列出的字段实际上是基本推送通知服务器所需的全部内容。数据库中的个人识别,设备条目的令牌,以便您知道谁将收到推送消息,而dateChanged是可选的,但很高兴知道您在数据库中有多长时间。

The three listed fields are really all you need for a basic push notification server. Personal identification in your database, the token for the device entry so you know who will receive the push message, and the dateChanged is optional but good to know how long you've had this in your database for.

回到流式推送通知的概念 - 你应该真正研究如何使用基本的PHP脚本一次发送多个通知(我已经用PHP完成了整个服务器100行代码,因此基于类的PHP可以非常简单。)

Going back to the concept of "streaming" push notifications - you should really look into how to send multiple notifications at once with a basic PHP script (I've done an entire server in PHP with less than 100 lines of code, so it can be pretty simple with class based PHP).

代码:

不幸的是,它需要占用大量空间来放置基本推送服务所需的所有代码,但我强烈建议您查看我上面提到的要点,以及下面列出的这个任务的一些非常棒的教程:

Unfortunately it would take up a lot of space to put all the code necessary for a basic push service but I highly recommend looking into the points I've mentioned above as well some pretty amazing tutorials for this task listed below:

  • http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12
  • http://mobile.tutsplus.com/tutorials/iphone/iphone-sdk_apns/

这篇关于如何将推送通知发送到特定设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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