1.在
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
方法中實(shí)現(xiàn)添加和分享的入口锅必,代碼如下 :
- (BOOL)application:(UIApplication *)application? didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIApplicationShortcutIcon *firstItemIcon = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeAdd];
UIMutableApplicationShortcutItem *firstItem = [[UIMutableApplicationShortcutItem alloc]initWithType:@"First" localizedTitle:@"添加" localizedSubtitle:nil icon:firstItemIcon userInfo:nil];
UIApplicationShortcutIcon *secondItemIcon = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeShare]; ???? ? ? ? ? UIMutableApplicationShortcutItem *secondItem = [[UIMutableApplicationShortcutItem alloc]initWithType:@"Second" localizedTitle:@"分享" localizedSubtitle:nil icon:secondItemIcon userInfo:nil]; ??? application.shortcutItems = @[firstItem,secondItem];
return YES;
}
2.實(shí)現(xiàn)這個(gè)方法
-(void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler
在這個(gè)方法中處理添加和分享的事件,代碼如下:
-(void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler{
if ([shortcutItem.type isEqual:@"add"])
{ ???????? NSLog(@"執(zhí)行添加事件");
}else if(
[shortcutItem.type isEqual:@"share"]
){
NSLog(@"執(zhí)行分享的操作 ");
}
}
二、通過模擬器進(jìn)行調(diào)試? 使用[SBShortcutMenuSimulator](
https://github.com/DeskConnect/SBShortcutMenuSimulator
)來配置模擬器,使模擬器支持3D Touch
在終端中按順序輸入以下命令:
1.git clone https://github.com/DeskConnect/SBShortcutMenuSimulator.git
2.cd SBShortcutMenuSimulator
3.make
然后打開剛才寫好的程序 運(yùn)行一下打開模擬器,再去終端中按順序輸入一下命令:
1.xcrun simctl spawn booted launchctl debug system/com.apple.SpringBoard
--environment DYLD_INSERT_LIBRARIES=$PWD/SBShortcutMenuSimulator.dylib
2.xcrun simctl spawn booted launchctl stop com.apple.SpringBoard
3.echo 'com.apple.mobilecal' | nc 127.0.0.1 8000
注意: 'com.apple.mobilecal' ''里邊寫的是自己項(xiàng)目的Bundle identifier.?這行命令就是要讓模擬器顯示出3D Touch,每次想要顯示快速入口只要重復(fù)操作即可