更新记录:

    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. 用Python开始机器学习(7:逻辑回归分类) --好!!

    from : http://blog.csdn.net/lsldd/article/details/41551797 在本系列文章中提到过用Python开始机器学习(3:数据拟合与广义线性回归)中提到 ...

  2. Google Kubernetes设计文档之服务篇-转

    摘要:Kubernetes是Google开源的容器集群管理系统,构建于Docker之上,为容器化的应用提供资源调度.部署运行.服务发现.扩容缩容等功能. Pod是创建.调度和管理的最小部署单位,本文详 ...

  3. 【转载】debian上快速搭建ftp

    转载自:http://suifengpiaoshi.diandian.com/post/2012-05-05/17955899 搭建ftp 包括搭建ftp服务器和ftp客户端 本文以debian上搭建 ...

  4. Sequence.js - 适合电子商务网站的图片滑块

    Sequence.js 是一个非常现代的图片滑动效果,特别适合电子商务网站或者企业产品展示功能.带有图片缩率图,能够呈现全屏图片浏览效果.结合 CSS3 Transition 实现响应式的滑块效果. ...

  5. MySQL忘记root密码的找回方法

    (1)登录到数据库所在服务器,手工kill掉MySQL进程: kill ' cat /mysql-data-directory/hostname.pid'     其中,/mysql-data-dir ...

  6. IOS开发UI基础 UIAlertView的属性

    UIAlertView1.Title获取或设置UIAlertView上的标题. 2.Message获取或设置UIAlertView上的消息 UIAlertView *alertView = [[UIA ...

  7. EF容器---代理类对象

    #region 修改--官方的修改是,先查询,然后修改 /// <summary> /// 修改--官方的修改是,先查询,然后修改 /// </summary> static ...

  8. background的属性和背景图片定位的实例

    本文内容: 1.背景图片定位示例 2.background常用的属性值 3.background-repeat新增的round.space属性 4.background-size的属性值(着重介绍co ...

  9. Dev 饼图

    // 添加引用命名空间 using DevExpress.XtraCharts; /* *具体步骤:(1)先构建饼图对象的数据源DataTable * (2)再设置饼图对象的相关参数 * (3)饼图空 ...

  10. C#继承基本控件实现自定义控件

    C#继承基本控件实现自定义控件 摘自:http://www.cnblogs.com/greatverve/archive/2012/04/25/user-control-inherit.html 自定 ...