2014-09-26 70 views
0

Apple是否打开了一个API,以便能够在锁定屏幕上向左滑动时创建功能?最好的方式来描述这个截图:用于在锁定屏幕上向左滑动的API - iOS 8

换句话说,我可以为我的应用程序特定推送通知创建自定义功能吗?例如,如果我向左滑动,我可以创建一个保存按钮来触发一些服务器端代码?

enter image description here

回答

2

是的,这是一个iOS 8功能。当你用新的SDK构建应用程序,您需要使用(这里简单的例子:Remote Notification iOS 8)新UIUserNotificationSettings注册通知

除此之外你需要定义自己的行为为一类是基本的例子。它可以去像这样:

UIMutableUserNotificationAction *yesAction = [[UIMutableUserNotificationAction alloc] init]; 
    yesAction.identifier = @"yes"; 
    yesAction.title = @"Yes"; 
    yesAction.activationMode = UIUserNotificationActivationModeForeground; 
    yesAction.destructive = NO; 
    yesAction.authenticationRequired = YES; 

    UIMutableUserNotificationAction *noAction = [[UIMutableUserNotificationAction alloc] init]; 
    noAction.identifier = @"no"; 
    noAction.title = @"No"; 
    noAction.activationMode = UIUserNotificationActivationModeBackground; 
    noAction.destructive = NO; 
    noAction.authenticationRequired = NO; 

    UIMutableUserNotificationCategory *yesNoActionsCategory = [[UIMutableUserNotificationCategory alloc] init]; 
    yesNoActionsCategory.identifier = @"YesNo"; 
    [yesNoActionsCategory setActions:@[yesAction, noAction] forContext:UIUserNotificationActionContextDefault]; // You may provide up to 4 actions for this context 
    [yesNoActionsCategory setActions:@[yesAction, noAction] forContext:UIUserNotificationActionContextMinimal]; 

通知和推式有效载荷将需要“YESNO”标识注册时,您会通过yesNoActionsCategory到您的设置。您的应用程序代表则需要使用此方法处理自定义操作: - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void (^)())completionHandler

来自WWDC 2014的What's New in iOS Notifications视频具有您所需的内容。上面的示例代码来自here以保存我的输入。

+0

感谢您的回复!只是在这里说你的帖子末尾的'here'链接重定向到http://community.ubudu.com/help/kb。看起来原来的帖子被(重新)移动了。 – tonchis 2015-08-19 13:31:23