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]

至此,消息推送基本功能的集成已经完成。

【转载自友盟消息推送iOS文档】在appDelegate中注册推送的更多相关文章

  1. 友盟消息推送api、python sdk问题、测试demo代码

    一,友盟消息推送python服务端sdk地址和文档地址 1.sdk地址:http://dev.umeng.com/system/resources/W1siZiIsIjIwMTYvMDgvMTkvMT ...

  2. 为友盟消息推送开发的PHP SDK(composer版):可以按省发Android push

    一直以来APP希望按省市县推送Android push,只能自己分析用户经纬度,打tag发送. 现在终于有服务商提供了. 友盟消息推送 可以“按省推送”,很方便. 我为友盟做了PHP SDK(comp ...

  3. .NET手记-友盟消息推送服务器端加密算法的实现

    最近为App开发消息推送功能,这里我们采用了友盟的消息推送服务,但其后台简陋,可定制化程度低,所以决定接入服务器端API,在自己的服务器上部署一套推送服务. 其中涉及到很多问题,首先要解决的就是与友盟 ...

  4. umeng友盟消息推送功能集成

    umeng友盟消息推送功能集成(本人使用的是eclipse开发) 1.首先请自行观看友盟消息推送集成的API文档. 观看地址如下: http://dev.umeng.com/push/android/ ...

  5. 友盟消息推送UPush

    第一步:把下载的SDK里面的PushSDK当做Module导入自己的项目 第二步:在自己项目的build.gradle里面一定要配置applicationId defaultConfig { appl ...

  6. 友盟消息push功能

    友盟地址:https://i.umeng.com/user/products 一.android 1.产品->U-App/U-push->立即使用->管理->左侧-集成测试-& ...

  7. iOS文档预览功能教程

     本文转载至 http://blog.csdn.net/devday/article/details/6580444   文档iosuinavigationcontrollerextensionmic ...

  8. RTX消息提醒工具设计文档

    为什么要做 项目上线后,系统依然由各业务模块负责人自己维护.而后台运行的各种业务服务结果,不能及时反馈到业务负责人.而等到客户反馈时则会太被动.为了能及时发现并解决项目问题,设计了该工具. 可利用资源 ...

  9. 友盟消息推送和更新XML配置

    <receiver android:name="com.umeng.message.NotificationProxyBroadcastReceiver" android:e ...

随机推荐

  1. hbase权威指南学习笔记--架构--存储

    HBase主要处理两种文件:预写日志(Write-Ahead Log,WAL),实际的数据文件. 一个基本的流程是客户端首先联系ZooKeeper子集群查找行健数据所在的region服务器名.(通过Z ...

  2. 用ant重新编译jdk加入调试信息

    (文章后面提供了ant和build.xml打包之后的build.zip下载,解压build.zip,然后将apache-ant-1.9.2-bin.zip解压即完成了ant安装,也可到http://a ...

  3. postgresql赋予/撤消 用户权限

    (1)给予权限:grant           grant select on 表名 to 用户名: (2)撤消权限:revoke           revoke select on 表名 from ...

  4. STC10F10XE定时器中断输出10KHz的方波程序

    //咱做硬件的也动手做点测试程序,为了测试新做的电机驱动板,找了个51的板子当10K信号发生器测试IGBT开关延时时间. #include <STC_NEW_8051.H>#include ...

  5. Js验证 :只能输入数字和小数点 验证是否是数字 js取float型小数点后两位

    JS判断只能是数字和小数点 1.文本框只能输入数字代码(小数点也不能输入)<input onkeyup="this.value=this.value.replace(/\D/g,'') ...

  6. Android实现自适应正方形GridView

    Android实现自适应正方形GridView  

  7. hash_map和map的区别

    hash_map和map的区别 分类: STL2008-10-15 21:24 5444人阅读 评论(0) 收藏 举报 class数据结构编译器存储平台tree 这里列几个常见问题,应该对你理解和使用 ...

  8. cf475B Strongly Connected City

    B. Strongly Connected City time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  9. Code Generation and T4 Text Templates

    Code Generation and T4 Text Templates Code Generation and T4 Text Templates

  10. Python常用模块(time, datetime, random, os, sys, hashlib)

    time模块 在Python中,通常有这几种方式来表示时间: 时间戳(timestamp) :         通常来说,时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量.我们运 ...