google 三星push servicee有用吗?

第三方登录:PushSharp是一个C#编写的服务端类库,用于推送消息到各种客户端,支持iOS(iPhone/iPad)、Android、Windows Phone、Windows 8、Amazo、Blackberry等设备。
官方网站:/Redth/PushSharp
当前最新稳定版本为2.0.4,支持通过NuGet获取(https://www.nuget.org/packages/PushSharp/)
提供了易于使用的API,支持以下平台的消息推送:
Apple (APNS – iPhone, iPad, OSX 10.8+):APNS即Apple Push Notification Service,详见:/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html
Android (GCM/C2DM - 手机及平板):GCM即Google Cloud Message,详见:/google/gcm/index.html
Chrome (GCM)
Amazon (ADM):ADM即Amazon Device Messaging,详见:/sdk/adm/setup.html
Windows Phone 7/7.5/8(包括FlipTile,CycleTile及IconicTile模板):详见:/en-us/library/windowsphone/develop/ff402558(v=vs.105).aspx
Blackberry (BIS and BES via PAP): 详见:/en/developers/deliverables/51382/
Firefox OS (即将支持)
100%的托管代码完全兼容Mono平台。
PushSharp主要包含以下程序集:
PushSharp.Core:(必选)核心组件
PushSharp.Apple:APNS,用于iOS及OSX
PushSharp.Android:C2DM及GCM,用于Android设备
PushSharp.Windows:用于Windows 8
PushSharp.WindowsPhone:用于WP设备
PushSharp.Amazon.Adm:用于Amazon的设备
PushSharp.Blackberry:用于黑莓设备
PushSharp.Google.Chrome:用于Chrome
其中,PushSharp.Core为必须的组件,其他的可以根据自己需要来选择对应平台。
平常使用只需要用NuGet来获取程序集即可:
Install-Package PushSharp这样会把主流平台的程序集(Apple/Android/Windows/WindowsPhone)都下载下来,可以根据自己需要删除用不到的平台组件。假如需要使用Blackberry等NuGet包里没有的组件,则需要到官方网站(/Redth/PushSharp)获取源码自行编译。对于Apple平台,只需要PushSharp.Core和PushSharp.Apple组件即可。 证书配置官方WIKI提供了详细的证书配置步骤:
Apple平台的证书配置:/Redth/PushSharp/wiki/How-to-Configure-&-Send-Apple-Push-Notifications-using-PushSharp
Android平台的证书配置(使用GCM情况下):/Redth/PushSharp/wiki/How-to-Configure-&-Send-GCM-Google-Cloud-Messaging-Push-Notifications-using-PushSharp Apple平台证书创建流程:
为AppID配置用于APP签名的证书:分别有开发环境(Development)和生产环境(Production)的证书
编辑AppID启用消息推送
为AppID创建用于消息推送(APNS)的证书(包括Development和Production)
下载以上证书并安装到Key Chain(钥匙串)
导出用于消息推送(APNS)的证书为.p12格式,并为它设置密码:用于在服务端推送消息 对于Apple平台需要特别说明:
Provisioning Protal现在已经变成了Certificates, Identifiers & Profiles,可以从Member Center点进去或者iOS Developer Center找到
对于已经发布的APP要启用消息推送功能,需要在Identifiers – App IDs找到对应的ID创建好APNS证书之后,再重新生成用于APP签名的证书,否则用于注册消息推送的代码(RegisterForRemoteNotificationTypes)不会正常工作,即返回的deviceToken为null
在使用Development证书调试应用程序时服务端需要使用Development APNS证书来推送消息,使用Production证书发布到AppStore后推送消息需要使用Production APNS证书来推送消息 客户端启用消息推送启用消息推送都是在AppDelegate里注册来完成的。对于使用objc语言编写的客户端:- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
if (application.enabledRemoteNotificationTypes == UIRemoteNotificationTypeNone)
[application registerForRemoteNotificationTypes:
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound];
application.applicationIconBadgeNumber = -1;
// Override point for customization after application launch.
return YES;}- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
NSString *pushToken = [[[[deviceToken description]
stringByReplacingOccurrencesOfString:@&&&withString:@&&]
stringByReplacingOccurrencesOfString:@&&& withString:@&&]
stringByReplacingOccurrencesOfString: @& & withString: @&&];
[[NSUserDefaults standardUserDefaults] setObject:pushToken forKey:@&pushtoken&]; // 保存起来}对于使用MonoTouch的客户端:
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
app.RegisterForRemoteNotificationTypes(
UIRemoteNotificationType.Alert |
UIRemoteNotificationType.Badge |
UIRemoteNotificationType.Sound);
app.ApplicationIconBadgeNumber = -1;
public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
string tokenStr = token.D
string pushToken = tokenStr.Replace(&&&, string.Empty).Replace(&&&, string.Empty).Replace(& &, string.Empty);
NSUserDefaults.StandardUserDefaults.SetString(pushToken, &pushtoken&);
public override void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action&UIBackgroundFetchResult& completionHandler)
}在接收到deviceToken的时候先存储在NSUserDefaults中,在用户登录的时候再取出来一起发送到服务端:NSString *pushToken = [[NSUserDefaults standardUserDefaults] stringForKey:@&pushtoken&]; //objcstring pushToken = NSUserDefaults.StandardUserDefaults.StringForKey(&pushtoken&); //MonoTouch服务端在用户登录成功之后,把接收到用户的用户名与pushToken关联起来,在推送消息的时候就可以针对指定用户来推送,具体的过程略。而对于不需要用户登录的app,可以在接收到deviceToken的时候直接发送到服务端。更多的客户端配置参考PushSharp源码的Client.Samples及PushSharp.Client目录。 服务端推送消息var pusher = new PushBroker();pusher.RegisterAppleService(new ApplePushChannelSettings(File.ReadAllBytes(&yourAppId.p12&), &证书的密码&));pusher.QueueNotification(
new AppleNotification()
.ForDeviceToken(pushToken) // 从数据库等地方获取设备的pushToken
.WithAlert(&测试iOS消息推送 - 囧月&)
.WithBadge(1)
.WithSound(&default&)
);在RegisterAppleService方法中可以注册多个APNS证书,PushSharp可以自动检测是Development/Production,这时候需要为证书设置标识:pusher.RegisterAppleService(new ApplePushChannelSettings(File.ReadAllBytes(&yourAppId.p12&), &证书的密码&), &证书标识如youAppId_development&);pusher.RegisterAppleService(new ApplePushChannelSettings(File.ReadAllBytes(&yourAppId.p12&), &证书的密码&), &证书标识如youAppId_production&);此外,可以注册各种事件来获得各种状态:pusher.OnDeviceSubscriptionChanged += pusher_OnDeviceSubscriptionCpusher.OnDeviceSubscriptionExpired += pusher_OnDeviceSubscriptionEpusher.OnNotificationSent += pusher_OnNotificationSpusher.OnNotificationFailed += pusher_OnNotificationFpusher.OnNotificationRequeue += pusher_OnNotificationRpusher.OnChannelCreated += pusher_OnChannelCpusher.OnChannelDestroyed += pusher_OnChannelDpusher.OnChannelException += pusher_OnChannelEpusher.OnServiceException += pusher_OnServiceEstatic void pusher_OnNotificationFailed(object sender, INotification notification, Exception error){
var n = (AppleNotification)
//error.Message ...获取推送出错的信息}static void pusher_OnNotificationSent(object sender, INotification notification){
//消息推送成功后
var n = (AppleNotification)
//n.Payload.Alert.Body
获取推送的消息内容...}static void pusher_OnDeviceSubscriptionExpired(object sender, string expiredSubscriptionId, DateTime expirationDateUtc, INotification notification){
// 从数据库删除过期的expiredSubscriptionId}static void pusher_OnDeviceSubscriptionChanged(object sender, string oldSubscriptionId, string newSubscriptionId, INotification notification){
// 把数据库中的oldSubscriptionId更新为newSubscriptionId}更多请参考源码的PushSharp.Sample目录。 参考官方网站:/Redth/PushSharp 可以获取最新源码及各种例子WIKI:/Redth/PushSharp/wiki  详细说明了各平台证书配置的方法PushService
JavaScript is disabled on your browser.
Class PushService
com.parse.PushService
All Implemented Interfaces:
public final class PushService
A service to listen for push notifications. This operates in the same process as the parent
application.
The PushService can listen to pushes from two different sources: Google Cloud Messaging
(GCM) or Parse's own push network. Parse will inspect your application's manifest at runtime and
determine which service to use for push. We recommend using GCM for push on devices that have
Google Play Store support. Parse uses its own push network for apps that want to avoid a
dependency on the Google Play Store, and for devices (like Kindles) which do not have Play Store
To configure the PushService for GCM, ensure these permission declarations are present in
your AndroidManifest.xml as children of the &manifest& element:
&uses-permission android:name="android.permission.INTERNET" /&
&uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&
&uses-permission android:name="android.permission.VIBRATE" /&
&uses-permission android:name="android.permission.WAKE_LOCK" /&
&uses-permission android:name="android.permission.GET_ACCOUNTS" /&
&uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /&
&permission android:name="YOUR_PACKAGE_NAME.permission.C2D_MESSAGE"
android:protectionLevel="signature" /&
&uses-permission android:name="YOUR_PACKAGE_NAME.permission.C2D_MESSAGE" /&
Replace YOUR_PACKAGE_NAME in the declarations above with your application's package name. Also,
make sure that com.parse.GcmBroadcastReceiver and com.parse.PushService are declared as children
of the &application& element:
&service android:name="com.parse.PushService" /&
&receiver android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND"&
&intent-filter&
&action android:name="com.google.android.c2dm.intent.RECEIVE" /&
&action android:name="com.google.android.c2dm.intent.REGISTRATION" /&
&category android:name="YOUR_PACKAGE_NAME" /&
&/intent-filter&
&/receiver&
Again, replace YOUR_PACKAGE_NAME with your application's package name.
To configure the PushService for Parse's push network, ensure these permission declarations are
present in your AndroidManifest.xml as children of the &manifest& element:
&uses-permission android:name="android.permission.INTERNET" /&
&uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&
&uses-permission android:name="android.permission.VIBRATE" /&
&uses-permission android:name="android.permission.WAKE_LOCK" /&
Also, make sure that
are declared as
children of the &application& element:
&service android:name="com.parse.PushService" /&
&receiver android:name="com.parse.ParsePushBroadcastReceiver" android:exported=false&
&intent-filter&
&action android:name="com.parse.push.intent.RECEIVE" /&
&action android:name="com.parse.push.intent.OPEN" /&
&action android:name="com.parse.push.intent.DELETE" /&
&/intent-filter&
&/receiver&
Note that you can configure the push service for both GCM and Parse's network by adding all the
declarations above to your application's manifest. In this case, Parse will use GCM on devices
with Play Store support and fall back to using Parse's network on devices without Play Store
support. If you want to customize the way your app generates Notifications for your pushes, you
can register a custom subclass of .
Once push notifications are configured in the manifest, you can subscribe to a push channel by
ParsePush.subscribeInBackground(&the_channel_name&);
When the client receives a push message, a notification will appear in the system tray. When the
user taps the notification, it will broadcast the &com.parse.push.intent.OPEN& intent.
listens to this intent to track an app open event and
launch the app's launcher activity. To customize this behavior override
Field Summary
Fields inherited from class&android.app.
, , , , , ,
Fields inherited from class&android.content.
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
Fields inherited from interface&android.content.
, , , , , ,
Constructor Summary
Constructors&
Constructor and Description
Client code should not construct a PushService directly.
Method Summary
Modifier and Type
Method and Description
Client code should not call onBind directly.
Client code should not call onCreate directly.
Client code should not call onDestroy directly.
int&flags,
int&startId)
Client code should not call onStartCommand directly.
Methods inherited from class&android.app.
, , , , , , , , , , , , ,
Methods inherited from class&android.content.
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
Methods inherited from class&android.content.
, , , , , , , , ,
Methods inherited from class&java.lang.
, , , , , , , , , ,
Constructor Detail
PushService
public&PushService()
Client code should not construct a PushService directly.
Method Detail
public&void&onCreate()
Client code should not call onCreate directly.
Overrides:
&in class&
onStartCommand
public&int&onStartCommand(&intent,
int&flags,
int&startId)
Client code should not call onStartCommand directly.
Overrides:
&in class&
public&&onBind(&intent)
Client code should not call onBind directly.
Specified by:
&in class&
public&void&onDestroy()
Client code should not call onDestroy directly.
Overrides:
&in class&关于APP退出,极光推送服务、以及其他三方服务的处理问题 - 开源中国社区
当前访客身份:游客 [
当前位置:
最近在开发一个Android版的客户端,里面基本的业务功能都实现了,现在进入了最后一个阶段...调试阶段...
但是遇到了一个问题,就是APP退出...
因为APP需要推送功能,于是加入了极光推送(JPush),另外里面还加入了 百度地图、百度定位插件。
因为使用了三方插件,它们都需要初始化,一般都选择在MainApplication(继承了Application类)的onCreate方法中初始化,避免重复初始化带来的时间消耗。所以在应用程序退出时,我们同样需要关闭他们、释放资源。
在网上查了下关于APP退出的资料,再看看OSChina里面的退出方法了解到(整个项目框架就是在OSchina客户端基础上搭的,在此谢谢将此项目开源的大神们!辛苦了!)
2.2版本之前
finishAllActivity();//结束所有Activity
ActivityManager activityMgr= (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
//关闭应用
//与当前应用相关的应用、进程、服务等也会被关闭。
//会发送 ACTION_PACKAGE_RESTARTED广播。
activityMgr.restartPackage(context.getPackageName());
System.exit(0);//退出应用
2.2版本之后官方建议使用
killBackgroundProcesses(String packageName)替代restartPackage(String packageName)
先使用此2种方法吧。测试,都可以退出应用,后台也没有输出任何东西,让后呢,后台服务到底有没有关闭呢,去设置-应用程序-运行中里看看吧;果然没有关闭掉,1个进程和1个服务——PushService依然挺立,应该可以理解为,其他初始化过的三方插件也没有主动关闭吧(百度地图的 service 是android:process=&:remote& 一个全局的进程;而百度定位没有service,不知道会不会随着应用终止一起释放资源...)
好吧,我理解为这些服务需要我退出前需先手动关闭,再退出程序
查了下极光推送的官方API,得到JPushInterface.stopPush(getApplicationContext())
好的先关闭三个插件服务,再结束所有Activity,再退出应用。
进入设置-应用程序里面看看,OK没有了!但是...突然发现日志中打印的记录发现MainApplication的onCreate方法被调用了...三个服务重新又被初始化了...再看设置-应用程序里面,进程又有了...只是启动时间重新计算了...说明,我们退出应用成功了...只是什么地方又触发了MainApplication重新启动...
去看看配置文件,发现极光推送服务的PushService的配置
&&&&android:name=&cn.jpush.android.service.PushService&
&&&&android:enabled=&true&
&&&&android:exported=&false&&
&&&&&intent-filter&
&&&&&&&&&action android:name=&cn.jpush.android.intent.REGISTER& /&
&&&&&&&&&action android:name=&cn.jpush.android.intent.REPORT& /&
&&&&&&&&&action android:name=&cn.jpush.android.intent.PushService& /&
&&&&&&&&&action android:name=&cn.jpush.android.intent.PUSH_TIME& /&&&&&&&&&&&&&&& &
&&&&&/intent-filter&
&/service&
&&&&android:name=&cn.jpush.android.service.PushReceiver&
android:enabled=&true& &
&&&&&intent-filter android:priority=&1000&&
&&&&&&&&&action android:name=&cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY& /&
&!--Required
显示通知栏 --&
&&&&&&&&&category android:name=&包名& /&
&&&&&/intent-filter&
&&&&&intent-filter&
&&&&&&&&&action android:name=&android.intent.action.USER_PRESENT& /&
&!-- 锁屏解除事件 --&
&&&&&&&&&action android:name=&android.net.conn.CONNECTIVITY_CHANGE& /&
&!-- 网络切换事件 --&
&&&&&/intent-filter&
&&&&&!-- Optional --&
&&&&&intent-filter&
&&&&&&&&&action android:name=&android.intent.action.PACKAGE_ADDED& /& &!-- 应用程序安装 --&
&&&&&&&&&action android:name=&android.intent.action.PACKAGE_REMOVED& /& &!-- 应用程序卸载 --&
&&&&&&&&&data android:scheme=&package& /&
&&&&&/intent-filter&
&/receiver&
我只能理解就是它了...不死的小强 - -
可是JPushInterface.stopPush(getApplicationContext())的解释是:
调用了本&API 后,JPush 推送服务完全被停止。具体表现为:
JPush Service 不在后台运行
收不到推送消息
JPushInterface.init 这个初始化方法调用,不能初始化 JPush 使得可以收到推送
极光推送所有的其他 API 调用都无效
如果官方给的这个方法仅仅暂时关闭服务,而注册过的事件又会再次启动服务,那这个关闭还有什么意义呢...
如果我要实现,退出应用,一个是完全退出,一个是后台运行,后台运行简单,关闭所有activity就行了...那如果是完全退出应用,即退出时关闭极光推送服务(或者理解为不再接受推送),要怎么办呢?或者说有什么好的策略呢?有更好的APP退出策略(涉及有后台Service的)求分享...
看了JPush虽然提供设置接收推送时间,但是...看了说明(如果不在该时间段内收到消息,当前的行为是:推送到的通知会被扔掉。)就直接放弃了...
本人初学Android时间不长,如有说错的地方大神们请见谅,口下留情...希望能给些建议,万分感谢!
共有5个答案
<span class="a_vote_num" id="a_vote_num_
作为一个普通用户,十分反感国产手机应用退出后,还驻留一堆服务在内存里面。
于是我用Autostarts(自启管理)禁用了所有程序的自启意图。
每次应用退出后,都手动去“应用-正在运行”里面手动关闭所有服务。
可即便是这样,还是会有一堆垃圾服务不知何时就偷偷冒出来,占用大量的内存、CPU和网络流量。
哎,android上的流氓太多,等有钱还是换一个iphone吧。。。
--- 共有 1 条评论 ---
其实一样的,只是 IOS 统一管理了 后台推送服务,google对于Android推送也有GCM,只是你懂的,国内无法稳定使用,没办法呀...
(3年前)&nbsp&
<span class="a_vote_num" id="a_vote_num_
JPushInterface.stopPush 之后服务会停止,但是服务在几分钟后会启动同步一下客户端SDK的状态,同步之后服务就不再启动了。所以stopPush是可以停止极关推送的服务的。
<span class="a_vote_num" id="a_vote_num_
Hi, 楼主,
我是极光推送 Javen。&
坦率地说,我们设计 JPush SDK stopPush 功能时,还真没有太考虑一个应用想要:退出时要杀死自己的情况。
因为,这不是一个好的实践,很明显是违反 Android/iOS 操作系统的设计的。智能手机 OS 设计的一个基本概念就是:App 的生命周期 OS 自己来管理。
一个应用退出后,进程是否立即退出,应该是 OS 层面来统一管理维护的。 如果你的 App 有 Servcie 长驻,的确整个进程被杀死(以释放必要的资源)的概率会小些。
JPush 提供 Push Service,大多数时候的应用场景是:应用在未使用时也能够收到消息。所以默认是&Service&长驻后台的。 JPush 提供 stopPush 方法,为有特殊需要的应用场景提供方便,PushService 不会长驻内存。 & 但为了维护完整性,JPush service 还是会被触发短期运行。
--- 共有 2 条评论 ---
不过发现会出现一个特别小概率的事件...
用户退出——请求清空别名——用户登陆——设置别名——清空别名超时再次尝试——设置别名成功——清空别名成功...
(3年前)&nbsp&
谢谢你的回答~发问题的时候才初学Android几个月...对APP的生命周期还不是很理解,特别是带后台常驻进程的...见笑了...
现在我采用清空别名的方式,让用户退出之后只会收到appkey级的推送。
(3年前)&nbsp&
<span class="a_vote_num" id="a_vote_num_
额。关注一下,顺便咨询一下用JPUSH的感受,开发难度和调试成本如何,支持多少用户
--- 共有 1 条评论 ---
还不错,推送及时率不错(看网络环境 - -),整合也很简单,自定义消息扩展性非常大...需求要求不高的话是个很好的选择。
(3年前)&nbsp&
<span class="a_vote_num" id="a_vote_num_
Activity都finish掉,自己的Service都stopSelf掉,其他的就别管了,本来Google就不希望大家手动去结束一个APP
--- 共有 1 条评论 ---
主要是这个极光推送的PushService,无法控制...官方提问,也是草草的给出答案JPushInterface.stopPush(this),所以我做的最坏打算也是这样的...不管了...再加个持久层属性,是否已手动退出,围绕它做判断了...但是感觉这是不是弯路呢....
(3年前)&nbsp&
更多开发者职位上
有什么技术问题吗?
FallenP...的其它问题
类似的话题君,已阅读到文档的结尾了呢~~
大容量云推送技术解析,有道云笔记最大容量,阿里云解析,阿里云域名解析,百度云解析种子失败,云窗无法解析参数,云解析,百度云下载地址解析,百度云地址解析,百度云解析种子
扫扫二维码,随身浏览文档
手机或平板扫扫即可继续访问
大容量云推送技术解析
举报该文档为侵权文档。
举报该文档含有违规或不良信息。
反馈该文档无法正常浏览。
举报该文档为重复文档。
推荐理由:
将文档分享至:
分享完整地址
文档地址:
粘贴到BBS或博客
flash地址:
支持嵌入FLASH地址的网站使用
html代码:
&embed src='/DocinViewer-4.swf' width='100%' height='600' type=application/x-shockwave-flash ALLOWFULLSCREEN='true' ALLOWSCRIPTACCESS='always'&&/embed&
450px*300px480px*400px650px*490px
支持嵌入HTML代码的网站使用
您的内容已经提交成功
您所提交的内容需要审核后才能发布,请您等待!
3秒自动关闭窗口

我要回帖

更多关于 三星push service 的文章

 

随机推荐