您的位置:首页 > 移动开发 > Android开发

Android/iOS Notification feature

2012-03-07 17:17 507 查看
notification有3种方案:

轮询 (poll)

长连接 (socket or http: comet)

push notification (c2dm for android, apple
notification server for

iPhone, 2者的原理是一样的:push server -> apn -> iPhone -> app installed in

iPhone

Poll: mobile app polls the server for new messagesperiodically

Advantages: easy to implement in CAP server side.

Disadvantage: mobile app has to send a http request to checklatest news periodically (e.g. send a request every 30 mins), it will killdevice battery.

Persistent TCP/IP: mobile app initiates along-lived mostly idle TCP/IP connection with the server and maintains it byoccasionally sending keepalive messages. Whenever there is something new on theserver, it sends a messages to the phone
over the TCP connection.

Advantages: Fully real-time updates.

Disadvantages: Hard to implement a reliable service on bothmobile device and the server side.

C2DM (for Android)/ APNS (for iOS device): they areios and android official recommended push notification solution. message can bepushed to user even if mobile app is not running in device.

APNS introduction: https://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW9
C2DM introduction: http://www.androidkit.com/cloud-to-device-messaging
push notification的方案(比较全)

http://www.zhishi5.com/jyxx/2012/0119/article_4019.html

android长连接的讨论

http://www.eoeandroid.com/thread-30241-3-1.html

长连接有2种:

1. 基于socket

* socket也有麻烦,因为要知道封装那些消息头,

socket也有好处,能实现同步异步机制,少一个进程

* 自己实现的socket的真正麻烦在于不容易穿透不同类型的网络,要达到那一步要做很多工作,而http在各个层次有很多的支持,容易穿透防火墙,局域网

2. 基于http (comet)

* http的长连接没多少人用

* 即使是长连接,http也必须要client先发起请求,在实际应用中有很多限制,别人做一个http长连接也只是为某些需求提供一个容易实现的方案,效果并不太好

Comet:基于 HTTP 长连接的“服务器推”技术

http://www.ibm.com/developerworks/cn/web/wa-lo-comet/

pocket长连接与http长连接的比较

http://topic.csdn.net/u/20110227/21/22484864-8d9c-4c4e-8dd9-24ff818ae3f0.html

android是使用Smack,它是XMPP一个比较流行的客户端lib

smack 源码分析一(android上实现长连接)

/article/7463326.html

smack 源码分析- PacketReader (android上实现长连接)

/article/7463328.html

smack 源码分析- PacketWriter (android上实现长连接)

/article/7463327.html

参考文档:

iOS

偷窥iPhone Push Notification的幕后: http://blog.csdn.net/ydfok/article/details/5732137
再论iPhone Push Notification: http://blog.csdn.net/ydfok/article/details/5732153
当app目前正在运行并在前端,如何处理push notification: http://stackoverflow.com/questions/1554751/how-to-handle-push-notification-if-application-is-already-running
下面这篇文章的"authentication"部分提到了如何把device绑定到user account: http://wiki.remobjects.com/wiki/Adding_Push_Notifications_to_Your_iPhone_Applications_Using_RemObjects_SDK_%28Xcode_%28iOS%29%29
iPhone push notification详解(推荐)

/article/1403520.html

/article/1403516.html

/article/1403515.html

/article/1403512.html

浅析最烦人的手机消息推送设计模式: http://write.blog.csdn.net/postedit/7329542

iphone push notification 消息推送 : http://blog.csdn.net/linkai5696/article/details/6316929
浅谈iPhone 中Push 功能原理 推送通知

http://mobile.51cto.com/iphone-276485.htm

解析iPhone Push Notification 消息推送 图文详细介绍

http://mobile.51cto.com/iphone-274033.htm

iPhone: 在程序里设置Push

http://mobile.51cto.com/iphone-273845.htm

iPhone: 基于HTTP长连接Server PUSH

http://mobile.51cto.com/iphone-278408.htm

iPhone 搭建PHP版Push服务器 实例操作

http://mobile.51cto.com/iphone-273924.htm

Android

Android notification 官方文档:

http://developer.android.com/guide/topics/ui/notifiers/index.html

http://developer.android.com/guide/topics/ui/notifiers/toasts.html

http://developer.android.com/guide/topics/ui/notifiers/notifications.html

Android Push Notification推播機制系列文章: http://lp43.blogspot.com/2012/02/android-push-notification.html
Android使用asynctask来做notification listener的问题: http://stackoverflow.com/questions/6143131/how-to-wake-up-start-not-running-app-from-c2dm-listener-on-android
不使用c2dm的android push notification方案: http://hi.baidu.com/heagle018/blog/item/f299029d36883a7654fb9654.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: