2014-09-26 37 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