How to implement interactive notifications ios8

后端 未结 5 1888
名媛妹妹
名媛妹妹 2020-12-24 14:26

I\'m creating a timed todo list app in which users can start a timer from a lock screen notification by swiping to reveal a start button. This is a new feature shown in iOS

5条回答
  •  悲&欢浪女
    2020-12-24 15:07

    For ios10 Actionable push use this

     UNAuthorizationOptions authOptions =
    UNAuthorizationOptionAlert
    | UNAuthorizationOptionSound
        | UNAuthorizationOptionBadge;
        [[UNUserNotificationCenter currentNotificationCenter]
         requestAuthorizationWithOptions:authOptions
         completionHandler:^(BOOL granted, NSError * _Nullable error) {
         }
         ];
    UNNotificationAction *ok = [UNNotificationAction actionWithIdentifier:@"OK"
                                                                               title:NSLocalizedString(@"OK", nil)
                                                                             options:UNNotificationActionOptionForeground];
        UNNotificationAction *cancel = [UNNotificationAction actionWithIdentifier:@"CANCEL"
                                                                                   title:NSLocalizedString(@"CANCEL", nil)
                                                                                 options:UNNotificationActionOptionForeground];
        NSArray *buttons = @[ ok, cancel ];
    
        // create a category for message failed
        UNNotificationCategory *buttonsAction = [UNNotificationCategory categoryWithIdentifier:@"ACTION_BUTTON"
                                                                                        actions:buttons
                                                                              intentIdentifiers:@[]
                                                                                        options:UNNotificationCategoryOptionCustomDismissAction];
    NSSet *categories = [NSSet setWithObjects:buttonsAction, nil];
    
        // registration
        [[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:categories];
    

提交回复
热议问题