xcode 如何在 iOS 8 应用程序中制作交互式通知?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25693608/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I make interactive notifications in iOS 8 app?
提问by Joseph
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 notification, you can type in a quick response.
在 iOS 8 中,通知有一项新功能,您可以向下滑动通知并执行操作。例如,当您从 iMessage 收到一条消息并在通知上向下滑动时,您可以输入快速回复。
I've been looking through docs on how to do this, but I couldn't find it. Does anyone know where I can find out how to do it this/ where it is in docs?
我一直在查看有关如何执行此操作的文档,但找不到它。有谁知道我在哪里可以找到如何做到这一点/它在文档中的位置?
采纳答案by kevinl
take a look at
看一眼
for details on widgets on the notification center as well as
有关通知中心小部件的详细信息以及
where UIMutableUserNotification is what you're looking for.
其中 UIMutableUserNotification 是您要查找的内容。
Note that this documentation is pre-release so it can be changed whenever production is pushed.
请注意,此文档是预发布的,因此可以在推送生产时对其进行更改。
回答by Anand Nanavaty
Note:- This is Step 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];
}
Note:- This is Step 2
注意:- 这是第 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/
注意:- 如果您想了解更多信息,请访问此链接。 https://nrj.io/simple-interactive-notifications-in-ios-8/
回答by Jordan Walsh
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:
我不相信这个答案,我只是在网上找到它,但它对帮助我理解 iOS8 交互式通知非常有用: