【问题标题】:How do I make interactive notifications in iOS 8 app?如何在 iOS 8 应用程序中制作交互式通知?
【发布时间】:2014-10-30 20:43:29
【问题描述】:

在 iOS 8 中,通知有一项新功能,您可以在其中向下滑动并执行操作。例如,当您收到来自 iMessage 的消息并在通知上向下滑动时,您可以输入快速回复。

我一直在查看有关如何执行此操作的文档,但找不到。有谁知道我在哪里可以找到如何做到这一点/它在文档中的位置?

【问题讨论】:

标签: ios xcode notifications push-notification ios8


【解决方案1】:

注意 :- 这是第 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];
}

注意 :- 这是第 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();
}
}

注意:- 如果您想了解更多信息,请访问此链接。 https://nrj.io/simple-interactive-notifications-in-ios-8/

【讨论】:

    【解决方案2】:

    看看

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

    有关通知中心小部件的详细信息以及

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

    UIMutableUserNotification 是您要查找的内容。

    请注意,此文档是预发布的,因此可以在推送生产时对其进行更改。

    【讨论】:

    • 在我看来不允许快速回复,只是按钮操作
    【解决方案3】:

    我不相信这个答案,我只是在网上找到它,但它对帮助我理解 iOS8 交互式通知非常有用:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-11
      • 1970-01-01
      • 2016-04-30
      相关资源
      最近更新 更多