iOS远程推送之友盟Push
更新记录:
1、2015年10月23日上午10:10分更新,优化了该类,去除了不必要的方法。
------------------------------------------------------------------------------------------------------------------------------------------------------
入职后的一个任务,就是做远程推送,听老大说用的是友盟Push.所以就看了一下友盟push,具体的集成以及证书的生成请参照这里。具体的就不再多说了,主要是自己重新封装了一下UMessage,具体的内容如下:
//
// ZGUmessagePush.h
// NotePad
//
// Created by zhanggui on 15/10/19.
// Copyright © 2015年 xiaoguizi. All rights reserved.
// #import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
#import "UMessage.h" @interface ZGUmessagePush : NSObject + (instancetype)shared; /** *设备注册友盟推送 */ + (void)registerUMessageWithOptions:(NSDictionary *)launchOptions; /** *注册设备deviceToken */ + (void)registerDeviceWithToken:(NSData *)data; /** *程序未运行的时候,推送消息的处理 * @param userInfo:推送过来的数据 */ + (void)handleNotRunAppRemoteUserInfo:(NSDictionary *)userInfo; /** *程序运行的时候,推送消息的处理 *@param userInfo:推送过来的数据 */ + (void)handleRunAppRemoteUserInfo:(NSDictionary *)userInfo; /** *默认的绑定用户账号 */ + (void)bandingDefaultCount; /** *解绑用户账号 */ + (void)unBandingDefaultCount; /** 绑定账号 @param account:要绑定的用户名 */ + (void)bandingTheCount:(NSString *)account; /** *解绑用户账号 */ + (void)unBandingTheCount; /** *添加标签 */ + (void)addTags:(NSArray *)tagArray; @end
以上是.h文件。
//
// ZGUmessagePush.m
// NotePad
//
// Created by zhanggui on 15/10/19.
// Copyright © 2015年 xiaoguizi. All rights reserved.
// #import "ZGUmessagePush.h" #import <UIKit/UIKit.h>
#import "LoginViewController.h"
#import "LeftTableViewController.h" #define _IPHONE80_ 80000
#define APPKEY @"5620da47e0f55a062b003b57" #define UMSYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending) @implementation ZGUmessagePush
+(instancetype)shared { static UFQUmessagePush *sharedPush = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ sharedPush = [[UFQUmessagePush alloc] init]; }); return sharedPush; } //#warning 需要修改为自己的APPKey + (void)registerUMessageWithOptions:(NSDictionary *)launchOptions { [UMessage startWithAppkey:APPKEY launchOptions:launchOptions]; #if __IPHONE_OS_VERSION_MAX_ALLOWED >= _IPHONE80_ if(UMSYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) { //register remoteNotification types (iOS 8.0及其以上版本) UIMutableUserNotificationAction *action1 = [[UIMutableUserNotificationAction alloc] init]; action1.identifier = @"action1_identifier"; action1.title=@"Accept"; action1.activationMode = UIUserNotificationActivationModeForeground;//当点击的时候启动程序 UIMutableUserNotificationAction *action2 = [[UIMutableUserNotificationAction alloc] init]; //第二按钮 action2.identifier = @"action2_identifier"; action2.title=@"Reject"; action2.activationMode = UIUserNotificationActivationModeBackground;//当点击的时候不启动程序,在后台处理 action2.authenticationRequired = YES;//需要解锁才能处理,如果action.activationMode = UIUserNotificationActivationModeForeground;则这个属性被忽略; action2.destructive = YES; UIMutableUserNotificationCategory *categorys = [[UIMutableUserNotificationCategory alloc] init]; categorys.identifier = @"category1";//这组动作的唯一标示 [categorys setActions:@[action1,action2] forContext:(UIUserNotificationActionContextDefault)]; UIUserNotificationSettings *userSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert categories:[NSSet setWithObject:categorys]]; [UMessage registerRemoteNotificationAndUserNotificationSettings:userSettings]; } else{ //register remoteNotification types (iOS 8.0以下) [UMessage registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound |UIRemoteNotificationTypeAlert]; } #else //register remoteNotification types (iOS 8.0以下) [UMessage registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound |UIRemoteNotificationTypeAlert]; #endif #if DEBUG [UMessage setLogEnabled:YES]; #endif } + (void)registerDeviceWithToken:(NSData *)data { [UMessage registerDeviceToken:data]; #if DEBUG NSString *deveiceToken = [NSString stringWithFormat:@"%@",data]; deveiceToken = [deveiceToken stringByReplacingOccurrencesOfString:@" " withString:@""]; NSLog(@"deveice-token:%@",deveiceToken); #endif } + (void)handleNotRunAppRemoteUserInfo:(NSDictionary *)userInfo { [UMessage setAutoAlert:NO]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"程序未运行的逻辑处理" message:[userInfo objectForKey:@"name"] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil]; [alert show]; } + (void)handleRunAppRemoteUserInfo:(NSDictionary *)userInfo { [UMessage setAutoAlert:NO]; if ([UIApplication sharedApplication].applicationState==UIApplicationStateActive) { //程序在前台时逻辑处理 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"程序在前台的逻辑处理" message:[userInfo objectForKey:@"name"] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil]; [alert show]; }else { //程序不在前台时的逻辑处理 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"程序不在前台的逻辑处理" message:[userInfo objectForKey:@"name"] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil]; [alert show]; } } + (void)bandingDefaultCount { [UMessage addAlias:[[NSUserDefaults standardUserDefaults] objectForKey:@"username"] type:UFenQiType response:^(id responseObject, NSError *error) { if (error) { NSLog(@"Fail to banding..."); } }]; } + (void)unBandingTheCount { [UMessage removeAlias:[[NSUserDefaults standardUserDefaults] objectForKey:@"username"] type:UFenQiType response:^(id responseObject, NSError *error) { if (error) { NSLog(@"Fail to banding..."); } }]; } + (void)addTags:(NSArray *)tagArray { if ([tagArray isKindOfClass:[NSArray class]]) { if ([tagArray count]==) { NSLog(@"没有添加任何tag..."); return; }else { [UMessage addTag:tagArray response:^(id responseObject, NSInteger remain, NSError *error) { if (error) { NSLog(@"Add tag fail..."); } }]; } } } @end
注意事项:
1、如果是开发环境的话,需要添加deviceToken到友盟推送后台。
2、程序通过推送开启的调用handleNotRunAppRemoteUserInfo:方法,程序本身已经开启,只是处于前台或者后台的的调用handleRunAppRemoteUserInfo:方法。
iOS远程推送之友盟Push的更多相关文章
- ios远程推送和python版push server相关笔记
今天研究了下ios的远程推送,网上的相关教程很多,做了一遍下来记录一下遇到的问题和注意事项(转载请注明) 1.证书及乱七八糟的配置 公钥:app id管理那儿的“Development Push SS ...
- IOS远程推送
IOS远程推送 一.关于推送通知 推送通知,也被叫做远程通知,是在iOS 3.0以后被引入的功能.是当程序没有启动或不在前台运行时,告诉用户有新消息的一种途径,是从外部服务器发送到应用程序上的.一般说 ...
- iOS远程推送原理及实现过程
➠更多技术干货请戳:听云博客 推送通知,是现在的应用必不可少的功能.那么在 iOS 中,我们是如何实现远程推送的呢?iOS 的远程推送原理又是什么呢?在做 iOS 远程推送时,我们会遇到各种各样的问题 ...
- iOS 远程推送通知
1.什么是推送通知 在某些特殊情况下,应用程序被动收到的以不同种界面形式出现的提醒信息 推送通知的作用:可以让不在前台运行的app通知app发生了改变 iOS中得推送通知种类 远程推送通知(Remot ...
- iOS 远程推送通知 详解
1: ios本地通知和远程通知 http://wangjun.easymorse.com/?p=1482 2: 苹果远程通知服务申请激活例图 (外国佬写的.) http://mobiforge.com ...
- IOS 远程推送通知(UIRemoteNotification)
● 什么是远程推送通知 ● 顾名思义,就是从远程服务器推送给客户端的通知(需要联网) ● 远程推送服务,又称为APNs(Apple Push Notification Services) ● ...
- iOS远程推送1
一.APNS 远程推送 1.所有的苹果设备,在联网状态下,都会与苹果服务器建立长连接. 2.长连接:就是只要联网了,就一直建立连接. 3.长连接的作用:时间校准,系统升级,查找我的iPhone. 4. ...
- [置顶] 手把手教你iOS消息推送证书生成以及Push消息
iOS推送消息是许多iOS应用都具备的功能,今天在给应用加推送功能,在生成证书的过程中,发生了各种令人蛋痛的事.下面就把步骤拿出来分享下: iOS消息推送的工作机制可以简单的用下图来概括: Provi ...
- iOS 远程推送消息解析及逻辑处理
关于远程推送的相关配置网上已经有足够多的教程,这里就不复述了.这里讲述当客户端收到推送消息后,应怎样对其进行相应的逻辑处理. 工程的AppDelegate.m文件里提供了如下方法: //当应用程序启动 ...
随机推荐
- 浅析I/O模型及其设计模式
前言 I/O在软件开发中的重要性无需多言,无论是在操作系统.网络协议.DBMS这种底层支撑软件还是在移动APP,大型网站服务器等应用软件的开发中都是最核心最重要的部分.特别是现在软件服务使用量和数据量 ...
- 《HelloGitHub月刊》第01期
<HelloGitHub月刊> 因为现在这个项目只有我自己做,只敢叫"月刊",希望有志同道合者,快点加入到这个项目中来!同时,如果您有更好的建议或者意见,欢迎联系我.联 ...
- Python3操作MySQL,查询数据并保存到文件中
我们在测试过程中,可能需要到数据库中拉去一些数据,为从测试准备.比如最近在做接口性能测试的时候,就需要很多数据来支撑,所以就需要的数据库去查询数据,下面就是python3 查询 mysql 并且保存到 ...
- ASP.NET运行时详解 生命周期入口分析
说起ASP.NET的生命周期,网上有很多的介绍.之前也看了些这方面的博客,但我感觉很多程序猿像我一样,看的时候似乎明白,一段时间过后又忘了.所以,最近Heavi花了一段时间研究ASP.NET的源代码, ...
- C#属性封装
1.属性封装是为了保护与之相对应的字段的,保证字段的读取和赋值是否符合要求 2.属性可以分为:读写,只读,只写 3.允许外部访问的变量一定要申明为属性 4.属性的本质就是两个方法. 5.自动属性 6. ...
- jquery选择器(原创)
jquery选择器大方向可以分为这样: 下面我们先来看看基本选择器总的CSS选择器: 1.标签选择器: $("element") 其中,参数element,表示待查找的HTML标记 ...
- 【C#】线程协作式取消
Microsoft .Net Framework 提供了一个标准的取消操作的模式.这个模式是协作式的,意味着你想取消的操作必须显示地支持取消. CLR为我们提供了两个类: System.Threadi ...
- 【JS复习笔记】03 继承
关于继承 好吧,说到底JS还是原型继承的,而不是类继承.所以在这个上面要经常用到prototype去继承另一个对象. 所有的构造器函数都约定命名为首字母大写的形式,并且不以首字母大写的形式拼写任何其它 ...
- socket调用流程的函数及数据结构
如有错误,欢迎指正. 如果需要,可以提供visio原文件. 参考: 1. <追踪Linux TCPIP代码运行--基于2.6内核> 2. Linux Kernel 2.6.26
- 在Android设备上判断设备是否支持摄像头
private boolean hasCamera(){ boolean hasCamera=false; PackageManager pm=getActivity().getPackageMana ...