推送模块设置

1.在libaray_configs.plist 文件中的 push_appkey 中设置在友盟平台上申请得到的appkey

2.xcode 中各种证书配置正确,然后在Target->Capabilities 打开Push Notification 开关


推送模块设置_第1张图片
屏幕快照 2017-07-14 上午9.58.32.png

3.引入库文件 UserNotifications.framework 、libz.tbd 添加静态库.a文件的搜索路径

推送模块设置_第2张图片
90FD6754-5A9F-49F4-9C30-B1FD10D407B9.png

4.初始化SDK和其他配置

#import "AppDelegate.h"
#import "RBPushManager.h"
#import 
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [RBPushManager applicationDidFinishLaunchingWithOptions:launchOptions];
    //iOS10必须加下面这段代码。
    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
    center.delegate = self;
    UNAuthorizationOptions types = UNAuthorizationOptionBadge|  UNAuthorizationOptionAlert|UNAuthorizationOptionSound;
    [center requestAuthorizationWithOptions:types completionHandler:^(BOOL granted, NSError * _Nullable error) {
        if (granted) {
            [application registerForRemoteNotifications];
        }
    }];
    return YES;
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
    [RBPushManager didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
//iOS10以下使用这个方法接收通知
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
    [RBPushManager didReceiveRemoteNotification:userInfo];
}
//iOS10新增:处理前台收到通知的代理方法
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler{
    NSDictionary * userInfo = notification.request.content.userInfo;
    if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
         [RBPushManager didReceiveRemoteNotification:userInfo];
    }
    completionHandler(UNNotificationPresentationOptionSound|UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionAlert);
}

//iOS10新增:处理后台点击通知的代理方法
-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler{
    NSDictionary * userInfo = response.notification.request.content.userInfo;
    if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
         [RBPushManager didReceiveRemoteNotification:userInfo];
    }
}

5.有关推送的其他功能调用

#import 

@interface RBPushManager : NSObject

/**
 处理收到的推送信息

 @param callback 收到推送信息回调
 */
+(void)handlePushInfos:(void (^)(NSDictionary *))callback;

/**
 初始化友盟推送SDK
 */
+(void)applicationDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions;


/**
 注册设备Token
 */
+(void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;


/**
 收到推送消息
 */
+(void)didReceiveRemoteNotification:(NSDictionary *)pushInfos;


/**
 为设备添加标签
 */
+(void)addDeviceTag:(NSString *)tag;


/**
 移除设备标签
 */
+(void)removeDeviceTag:(NSString *)tag;


/**
 获取设备的标签列表
 */
+(void)getAllTags:(void (^)(NSSet *))callback;


/**
 删除设备上的所有标签
 */
+(void)removeAllTags;



/**
 设备设置别名
 */
+(void)setAlias:(NSString *)name type:(NSString *)type;


/**
 删除设备别名
 */
+(void)removeAlias:(NSString *)name type:(NSString *)type;
@end

你可能感兴趣的:(推送模块设置)