How do I make interactive notifications in iOS 8 app?

前端 未结 3 411
执念已碎
执念已碎 2021-01-01 06:24

In iOS 8, there is a new feature to notifications where you can slide down on it and do an action. For example, when you get a message from iMessage and slide down on the no

相关标签:
3条回答
  • 2021-01-01 07:02

    Note :- This is Step 1

    NSString * const NotificationCategoryIdent  = @"ACTIONABLE";
    NSString * const NotificationActionOneIdent = @"ACTION_ONE";
    NSString * const NotificationActionTwoIdent = @"ACTION_TWO";
    
    - (void)registerForNotification {
    
    UIMutableUserNotificationAction *action1;
    action1 = [[UIMutableUserNotificationAction alloc] init];
    [action1 setActivationMode:UIUserNotificationActivationModeBackground];
    [action1 setTitle:@"Action 1"];
    [action1 setIdentifier:NotificationActionOneIdent];
    [action1 setDestructive:NO];
    [action1 setAuthenticationRequired:NO];
    
    UIMutableUserNotificationAction *action2;
    action2 = [[UIMutableUserNotificationAction alloc] init];
    [action2 setActivationMode:UIUserNotificationActivationModeBackground];
    [action2 setTitle:@"Action 2"];
    [action2 setIdentifier:NotificationActionTwoIdent];
    [action2 setDestructive:NO];
    [action2 setAuthenticationRequired:NO];
    
    UIMutableUserNotificationCategory *actionCategory;
    actionCategory = [[UIMutableUserNotificationCategory alloc] init];
    [actionCategory setIdentifier:NotificationCategoryIdent];
    [actionCategory setActions:@[action1, action2] 
                    forContext:UIUserNotificationActionContextDefault];
    
    NSSet *categories = [NSSet setWithObject:actionCategory];
    UIUserNotificationType types = (UIUserNotificationTypeAlert|
                                    UIUserNotificationTypeSound|
                                    UIUserNotificationTypeBadge);
    
    UIUserNotificationSettings *settings;
    settings = [UIUserNotificationSettings settingsForTypes:types
                                                 categories:categories];
    
    [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
    }
    

    Note :- This is Step 2

    - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void (^)())completionHandler {
    
    if ([identifier isEqualToString:NotificationActionOneIdent]) {
    
        NSLog(@"You chose action 1.");
    }
    else if ([identifier isEqualToString:NotificationActionTwoIdent]) {   
    
        NSLog(@"You chose action 2.");
    }    
    if (completionHandler) {
    
        completionHandler();
    }
    }
    

    Note :- If you want to learn more, Visit this link. https://nrj.io/simple-interactive-notifications-in-ios-8/

    0 讨论(0)
  • 2021-01-01 07:10

    I take no credit for this answer, I just found it online but it was very useful in helping my understanding of iOS8 Interactive Notifications:

    http://docs.appcelerator.com/titanium/3.0/#!/guide/iOS_Interactive_Notifications-section-40930452_iOSInteractiveNotifications-CreateaNotificationAction

    0 讨论(0)
  • 2021-01-01 07:24

    take a look at

    https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/ExtensibilityPG/NotificationCenter.html

    for details on widgets on the notification center as well as

    https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIMutableUserNotificationCategory_class/index.html#//apple_ref/doc/uid/TP40014610

    where UIMutableUserNotification is what you're looking for.

    Note that this documentation is pre-release so it can be changed whenever production is pushed.

    0 讨论(0)
提交回复
热议问题