Developer/iOS

[iOS9] ShotCutItem (QuickAction) 퀵액션 추가하기

블로blow 2015. 12. 3. 16:40
728x90



이번 iOS9에서 제공되는 3d touch를 이용해 QuickAction(퀵액션)을 추가하겠습니다.


위의 화면과 같이 iOS9에서 제공되는 ShotCutItem 추가하는 방법을 알아 보겠습니다.


1. info.plist

<key>UIApplicationShortcutItems</key>
<array>
<dict>
<key>UIApplicationShortcutItemTitle</key>
<string>Action1</string>
<key>UIApplicationShortcutItemType</key>
<string>com.action1</string>
<key>UIApplicationShortcutItemIconType</key>
<string>UIApplicationShortcutIconTypeConfirmation</string>
</dict>
</array>


2. code

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    //shortcutitem add
    UIApplicationShortcutItem *item1 = [[UIApplicationShortcutItem alloc] initWithType:@"com.action2" localizedTitle:@"Action2" localizedSubtitle:@"title2" icon:[UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeLove] userInfo:nil];
    UIApplicationShortcutItem *item2 = [[UIApplicationShortcutItem alloc] initWithType:@"com.action3" localizedTitle:@"Action3" localizedSubtitle:@"title3" icon:[UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeCloud] userInfo:nil];
    UIApplicationShortcutItem *item3 = [[UIApplicationShortcutItem alloc] initWithType:@"com.action4" localizedTitle:@"Action4" localizedSubtitle:nil icon:[UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeTask] userInfo:nil];

    [[UIApplication sharedApplication] setShortcutItems: @[ item1, item2, item3 ]];

    return YES;
}



아이템을 클릭해 실행하면 다음의 코드의 델리게이트가 실행됩니다.

AppDelegate.m

//shortcutitem start delegate
- (void)application:(UIApplication *)application performActionForShortcutItem:(nonnull UIApplicationShortcutItem *)shortcutItem completionHandler:(nonnull void (^)(BOOL))completionHandler {
    NSLog(@"%@", [shortcutItem description]);
}




참고 : https://github.com/minjoongkim/iOS-3D-Touch-Example

728x90