0

Did Apple open up an API to be able to create functionality for when you swipe to the left on the lock screen? The best way for me to describe this is with a screenshot:

In other words, could I create custom functionality for my app specific push notification? For example, if I swiped to the left I could create a save button that triggers some server-side code?

enter image description here

Apollo
  • 8,874
  • 32
  • 104
  • 192

2 Answers2

2

Yes, this is an iOS 8 feature. When you build your app with the new SDK you'll need to register for notifications using the new UIUserNotificationSettings (simple example here: Remote Notification iOS 8)

Beyond that basic example you'll need to define your actions into a category. It could go something like this:

    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];

You would pass yesNoActionsCategory into your settings when registering for notifications and your push payload would need the "YesNo" identifier. Your app delegate then needs to handle the custom actions with this method: - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void (^)())completionHandler

The What's New in iOS Notifications video from WWDC 2014 has what you need. The sample code above came from here to save my typing.

Community
  • 1
  • 1
Anthony
  • 2,867
  • 1
  • 17
  • 17
  • Thanks for the reply! Just here to say the `here` link at the end of your post redirects to http://community.ubudu.com/help/kb. Looks like the original post was (re)moved. – tonchis Aug 19 '15 at 13:31
0

What you are looking for are User Actions.

The official documentation can be found here: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIAlertController_class/#//apple_ref/doc/uid/TP40014538-CH1-SW8

Using this method, you should be able to add an action with a specific selector -- which would do whatever you need done on the server.

Garett
  • 552
  • 6
  • 15