概述
1.2 基本功能集成指南
提示
请先在友盟的消息推送管理后台中创建App,获得AppKey和AppSecret
-
导入SDK
- 下载 UMessage_Sdk_All_x.x.x.zip并解压缩
- 导入插件
所需SDK文件夹:
UMessage_Sdk_x.x.x
请在你的工程目录结构中,右键选择Add->Existing Files…
,选择这个文件夹。或者将这个文件夹拖入XCode工程目录结构中,在弹出的界面中勾选Copy items into destination group's folder(if needed)
, 并确保Add To Targets
勾选相应的target。 -
配置(可选)
- SDK采用ARC管理内存,非ARC项目也是默认支持,如遇问题,请联系我们
- 如果您使用了
-all_load
,可能需要添加libz
的库:TARGETS
-->Build Phases
-->Link Binary With Libraries
-->+
-->libz.dylib
说明
SDK支持iOS 4.3+ -
添加代码
-
定义宏
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)#define iOS8 SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")
-
打开*AppDelegate.m
,依次按照以下步骤集成:didFinishLaunchingWithOptions
中的设置:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //set AppKey and AppSecret [UMessage startWithAppkey:@"your appkey" launchOptions:launchOptions]; #if __IPHONE_OS_VERSION_MAX_ALLOWED >= _IPHONE80_
if(iOS8)
{
//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
//for log
[UMessage setLogEnabled:YES];
return YES;
}
didRegisterForRemoteNotificationsWithDeviceToken
中设置
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { [UMessage registerDeviceToken:deviceToken]; }
didReceiveRemoteNotification
中设置
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { [UMessage didReceiveRemoteNotification:userInfo]; }
说明
如需关闭推送,请使用[UMessage unregisterForRemoteNotifications]
至此,消息推送基本功能的集成已经完成。
转载于:https://www.cnblogs.com/Bo-tree/p/5077727.html
最后
以上就是感性萝莉为你收集整理的【转载自友盟消息推送iOS文档】在appDelegate中注册推送的全部内容,希望文章能够帮你解决【转载自友盟消息推送iOS文档】在appDelegate中注册推送所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复