美文网首页
关于友盟推送

关于友盟推送

作者: 招牌猪 | 来源:发表于2016-05-07 00:06 被阅读951次

    这是一篇关于友盟推送的集成

    1.首先,需要创建appid,创建的时候需要勾选push Notifications , bundeID要和工程名字保持一致,然后点击continue,之后继续创建,首先是开发证书,选中在电脑中自己导出的cer文件,cer文件的创建从钥匙串中导出,创建一个cer文件,然后点击上传,成功后可以下载他的开发者证书,把他存入本地,然后从钥匙串中导出p12文件,生产者证书一样的道理

    2.创建友盟的账号和密码,然后创建应用,讲开发者证书和生产者证书p12上传到应用中,服务器就如果测试的话就填自己的ip地址,公司的服务器就填公司的,创建之后就得到他的appkey和appscres,记录下来,下载最新的SDK,导入UMessage_Sdk_x.x.xh中的文件

    3.创建工程,如果是ios9.0以上的用户需要先配置一下

    详情去看:http://dev.umeng.com/push/ios/ios9filter

    保持bundID和创建的appid时候bundID一致

    4.导入

    #import "UMessage.h"

    #define APPKEY @"572cb4d867e58ed140000052"

    #define APPSecret @"yldutas9tnmbcd0hbfkkfqjidgbdrqzy"

    #define UMSYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

    #define _IPHONE80_ 80000

    然后在在下面设置

    [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

    //for log

    [UMessage setLogEnabled:YES];

    下面设置他的代理获取他的token

    - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken

    {

    [UMessage registerDeviceToken:deviceToken];

    }

    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

    {

    [UMessage didReceiveRemoteNotification:userInfo];

    }

    相关文章

      网友评论

          本文标题:关于友盟推送

          本文链接:https://www.haomeiwen.com/subject/njijrttx.html