更新记录:

    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的更多相关文章

  1. ios远程推送和python版push server相关笔记

    今天研究了下ios的远程推送,网上的相关教程很多,做了一遍下来记录一下遇到的问题和注意事项(转载请注明) 1.证书及乱七八糟的配置 公钥:app id管理那儿的“Development Push SS ...

  2. IOS远程推送

    IOS远程推送 一.关于推送通知 推送通知,也被叫做远程通知,是在iOS 3.0以后被引入的功能.是当程序没有启动或不在前台运行时,告诉用户有新消息的一种途径,是从外部服务器发送到应用程序上的.一般说 ...

  3. iOS远程推送原理及实现过程

    ➠更多技术干货请戳:听云博客 推送通知,是现在的应用必不可少的功能.那么在 iOS 中,我们是如何实现远程推送的呢?iOS 的远程推送原理又是什么呢?在做 iOS 远程推送时,我们会遇到各种各样的问题 ...

  4. iOS 远程推送通知

    1.什么是推送通知 在某些特殊情况下,应用程序被动收到的以不同种界面形式出现的提醒信息 推送通知的作用:可以让不在前台运行的app通知app发生了改变 iOS中得推送通知种类 远程推送通知(Remot ...

  5. iOS 远程推送通知 详解

    1: ios本地通知和远程通知 http://wangjun.easymorse.com/?p=1482 2: 苹果远程通知服务申请激活例图 (外国佬写的.) http://mobiforge.com ...

  6. IOS 远程推送通知(UIRemoteNotification)

    ●  什么是远程推送通知 ●  顾名思义,就是从远程服务器推送给客户端的通知(需要联网) ●  远程推送服务,又称为APNs(Apple Push Notification Services) ●   ...

  7. iOS远程推送1

    一.APNS 远程推送 1.所有的苹果设备,在联网状态下,都会与苹果服务器建立长连接. 2.长连接:就是只要联网了,就一直建立连接. 3.长连接的作用:时间校准,系统升级,查找我的iPhone. 4. ...

  8. [置顶] 手把手教你iOS消息推送证书生成以及Push消息

    iOS推送消息是许多iOS应用都具备的功能,今天在给应用加推送功能,在生成证书的过程中,发生了各种令人蛋痛的事.下面就把步骤拿出来分享下: iOS消息推送的工作机制可以简单的用下图来概括: Provi ...

  9. iOS 远程推送消息解析及逻辑处理

    关于远程推送的相关配置网上已经有足够多的教程,这里就不复述了.这里讲述当客户端收到推送消息后,应怎样对其进行相应的逻辑处理. 工程的AppDelegate.m文件里提供了如下方法: //当应用程序启动 ...

随机推荐

  1. SNF开发平台WinForm之十一-程序打包-SNF快速开发平台3.3-Spring.Net.Framework

    原来我们用的是微软自带的打包工具去打包,但感觉好像也是第三方做的打包并且很是麻烦,还有时不成功报错.那综合考虑就找一个简单实用的打包工具吧,就找到了NSIS这个.具体打包步骤如下: 1.安装NSIS ...

  2. Mina、Netty、Twisted一起学(二):TCP消息边界问题及按行分割消息

    在TCP连接开始到结束连接,之间可能会多次传输数据,也就是服务器和客户端之间可能会在连接过程中互相传输多条消息.理想状况是一方每发送一条消息,另一方就立即接收到一条,也就是一次write对应一次rea ...

  3. linux VM复制多个IP配置出错的处理

    device eth0 does not seem to be present, delaying initialization (2012-09-13 21:16:38) 转载▼ 标签: 杂谈   ...

  4. WCF学习之二

    今天在照着网上教程做练习的时候,用IE浏览器运行的时候遇到了一些问题 “找不到类型“WCFService.Service1”,它在 ServiceHost 指令中提供为 Service 特性值,或在配 ...

  5. Xcode-调试断点不能停在代码区终极解决方案

    转发 调试断点不能停在代码区终极解决方案:  http://mobile.51cto.com/iphone-390082.htm

  6. VM不能连入局域网

    如果选了Host-only,那么虚拟机与跑虚拟机的宿主就无法连通了. 可以选用Bridged模式,那么虚拟机与跑虚拟机的主机连通了

  7. SQL Server 2014里的IO资源调控器

    在本文中,我们将来看看SQL Server 2014在资源调控器方面增加了哪些新的功能.资源调控器(Resource Governor)是从SQL Server 2008开始出现的一项功能.它是用于管 ...

  8. SQL SERVER2008及以上版本数据库自动备份的三种方法

    方法一:创建一个维护计划对数据库进行备份 方法二:创建一个SQL作业对数据库进行备份 方法三:创建WINDOWS任务计划对数据库进行备份 方法一与方法二其实原理基本相同,都必需开启SQL代理服务,都会 ...

  9. TinyFox在VS2015上的调试器

    这个一个TinyFox在VS2015上的调试工具 : 开源了 https://github.com/maxzhang1985/TinyFoxDEBUG 开发这个工具的初衷,是想更便捷的调试Nancy ...

  10. 四则运算APP(BUG发掘)

    BUG: 1.有几率会出现一样的题目. 2.题目会出现两个一样的答案. 3.做题结束后不能返回主界面或者重新开始. 感想: 1.题目应该按年级分类出题. 2.主界面可以添加更多功能 如自己输入题目数, ...