swift中友盟推送

在oc中的一段话:

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= _IPHONE80_
    if(UMSYstem_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0"))
    {
        //register remoteNotification types
        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
        [UMessage registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge
         |UIRemoteNotificationTypeSound
         |UIRemoteNotificationTypeAlert];
    }
#else
    
    //register remoteNotification types
    [UMessage registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge
     |UIRemoteNotificationTypeSound
     |UIRemoteNotificationTypeAlert];
    
#endif

然后翻译成swift为:
if (UIDevice.currentDevice().systemVersion.compare("8.0.0") == .OrderedSame || UIDevice.currentDevice().systemVersion.compare("8.0.0") == .OrderedDescending){
            let action1 = UIMutableuserNotificationAction();
            action1.identifier = "action1_identifier"
            action1.title = "Accept"
            action1.activationMode = UIUserNotificationActivationMode.Foreground//当点击的时候启动程序
            
            let action2 = UIMutableuserNotificationAction();//第二按钮
            action2.identifier = "action2_identifier"
            action2.title = "Reject"
            action2.activationMode = UIUserNotificationActivationMode.Background
            action2.authenticationrequired = true
            action2.destructive = true
            
            let categorys = UIMutableuserNotificationCategory();
            categorys.identifier = "category1";//这组动作的唯一标示
            categorys.setActions([action1,action2],forContext: UIUserNotificationActionContext.Default)
            
            
            let userSettings = UIUserNotificationSettings(forTypes:[
                .Badge,.sound,.Alert],categories: Set(arrayLiteral: categorys))
            
            UMessage.registerRemoteNotificationAndUserNotificationSettings(userSettings)
        } else {
            UMessage.registerForRemoteNotificationTypes([.Badge,.Alert])
        }

相关文章

软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘...
现实生活中,我们听到的声音都是时间连续的,我们称为这种信...
前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿...
【Android App】实战项目之仿抖音的短视频分享App(附源码和...
前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至...
因为我既对接过session、cookie,也对接过JWT,今年因为工作...