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文件里提供了如下方法: //当应用程序启动 ...
随机推荐
- 实战android菜单项之XML加载菜单与动态菜单项[转]
原文地址:http://blog.csdn.net/kaiwii/article/details/7767225 自定义android应用程序的菜单项首先要知道切入点.经过学习,知道主要是两个Acti ...
- Linux内核Makefile文件(翻译自内核手册)
--译自Linux3.9.5 Kernel Makefiles(内核目录documention/kbuild/makefiles.txt) kbuild(kernel build) 内核编译器 Thi ...
- bootstrap插件学习-bootstrap.tab.js
先看bootstrap-tab.js的结构 var Tab = function ( element ) {} //构造器 Tab.prototype ={} //构造器的原型 $.fn.tab = ...
- Linux - Yum的常用方法总结
简述 rpm是由红帽公司开发的软件包管理方式,使用rpm可以方便的进行软件的安装.查询.卸载.升级等工作. 但是rpm软件包之间的依赖性问题往往会很繁琐,尤其是软件由多个rpm包组成时. Yum(全称 ...
- SQL查询语句去除重复行
1.存在两条完全相同的纪录 这是最简单的一种情况,用关键字distinct就可以去掉 select distinct * from table(表名) where (条件) 2.存在部分字段相同的纪录 ...
- C++ 多态的实现原理与内存模型
多态在C++中是一个重要的概念,通过虚函数机制实现了在程序运行时根据调用对象来判断具体调用哪一个函数. 具体来说就是:父类类别的指针(或者引用)指向其子类的实例,然后通过父类的指针(或者引用)调用实际 ...
- linux 系统管理 使用技巧
一.这篇文章讲了什么? 这篇文章很有参考性哈.本来是想等一段时间有更多条技巧后在发布的,不过,突然发现,我是去年的今天在博客园落户了,祝我的博客一周岁快乐,希望以后多分享一些文章啦.所以就把草稿箱的其 ...
- 无锁数据结构(Lock-Free Data Structures)
一个星期前,我写了关于SQL Server里闩锁(Latches)和自旋锁(Spinlocks)的文章.2个同步原语(synchronization primitives)是用来保护SQL Serve ...
- sprint演示Scrum 项目7.0
1.坚持所有的sprint都结束于演示. 团队的成果得到认可,会感觉很好. 其他人可以了解你的团队在做些什么,并得到重要反馈. 演示是一种社会活动,不同的团队可以在这里相互交流,讨论各自的工作.这很有 ...
- HNU 13308 Help cupid
Help cupid Problem's Link: http://acm.hnu.cn/online/?action=problem&type=show&id=13308&c ...