博客> UM推送
UM推送
2019-11-14 21:54 评论:0 阅读:701 企鹅会飞
UM最基本的东西

工作那么久,却从来没有写过相关博客,这是病得治,现在就开始治疗,今天讲一讲关于UM推送的事 第一步:下载友盟推送SDK集成到应用 这个就不多说了,UM官网讲得比我要详细得多。 第二步:IOS上实现推送功能的代码 如下(部分代码) 1、UMKey

  • (BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions { //asdf;lajksdfl;asdfl;

    /友盟推送/ [UMessage startWithAppkey:@"你的应用AppKey" launchOptions:launchOptions];

if __IPHONE_OS_VERSION_MAX_ALLOWED >= IPHONE80

if(UMSYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"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];
}

2、注册设备token

  • (void)application:(UIApplication )application didRegisterForRemoteNotificationsWithDeviceToken:(NSData )deviceToken { //下面这个token是将获取的nsdata转换成String,应为指定推送时我们需要将这个传给服务端。 NSString *token=[NSString stringWithFormat:@"%@",[[[[deviceToken description] stringByReplacingOccurrencesOfString: @"<" withString: @""] stringByReplacingOccurrencesOfString: @">" withString: @""] stringByReplacingOccurrencesOfString: @" " withString: @""]]; //注册token [UMessage registerDeviceToken:deviceToken]; }
收藏
0
sina weixin mail 回到顶部