国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

iOS遠程推送之友盟Push

2019-11-14 18:06:50
字體:
來源:轉載
供稿:網友

  更新記錄:

    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]==0) {            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:方法。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 双江| 天峻县| 大姚县| 曲沃县| 南投市| 浦江县| 凉城县| 清涧县| 涿州市| 赫章县| 保德县| 南丰县| 凤山县| 东丽区| 波密县| 江陵县| 宝兴县| 河西区| 吉隆县| 隆回县| 汉阴县| 泸水县| 静宁县| 黑龙江省| 屯昌县| 京山县| 正定县| 遂川县| 沿河| 方山县| 河西区| 浦东新区| 清新县| 庄浪县| 龙山县| 桦甸市| 安塞县| 盱眙县| 潢川县| 山阳县| 泸定县|