It is said that Apple, a mysterious team behind closed doors in research and development for many years 3DTouch Finally, applied to the iOS9, and exposed the API.
Press the APP icon on the system main screen and the custom menu will appear
There are two ways to achieve
A. Code (this method can also dynamically change the contents and functions of the 3DTouch menu):
The first step: Customizing a method of initializing the menu;
-(void) init3dtouch{if([[Uidevice Currentdevice] Systemversion].floatvalue <9.0) { return; } uiapplication*app =[UIApplication sharedapplication]; Nsmutablearray*its =[[App Shortcutitems] mutablecopy]; if(Its.count = =0) {Nsmutablearray*items =[[Nsmutablearray alloc] init]; Uiapplicationshortcuticon*icon2 =[Uiapplicationshortcuticon Iconwithtype:uiapplicationshortcuticontypeadd]; Uiapplicationshortcutitem*i2 = [[Uiapplicationshortcutitem alloc] Initwithtype:@"Com.xiaomi.i2"Localizedtitle:@"Initiate group chat"Localizedsubtitle:@""Icon:icon2 Userinfo:nil]; [Items Addobject:i2]; Uiapplicationshortcuticon*icon =[Uiapplicationshortcuticon Iconwithtype:uiapplicationshortcuticontypeshare]; Uiapplicationshortcutitem*I1 = [[Uiapplicationshortcutitem alloc] Initwithtype:@"com.xiaomi.i1"Localizedtitle:@"conference Call"Localizedsubtitle:@""Icon:icon Userinfo:nil]; [Items ADDOBJECT:I1]; [App Setshortcutitems:items]; }}
The second step: Implement the UIApplication protocol to respond to the system homepage Press the app appears menu, menu corresponding Click event;
-(void) Application: (UIApplication *) application Performactionforshortcutitem: (Uiapplicationshortcutitem *) ShortcutItem Completionhandler: (void(^) (BOOL)) completionhandler{if([Shortcutitem.type isequaltostring:@"com.xiaomi.i1"]) { //Click on the menu "launch group chat" To do the content } Else if([Shortcutitem.type isequaltostring:@"Com.xiaomi.i2"]){ //Click on the menu two ' teleconference ' to execute the content }}//called when the user activates your application by selecting a shortcut on the home screen,//except When-application:willfinishlaunchingwithoptions:or-application:didfinishlaunchingwithoptions returns NO.
Step three: Judge launchoptions! = nil to return no; Get the active App object and manually perform the clicked menu event
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {[Self init3dtouch]; //when the app is no longer running in the background, the 3DTouch activation app,launchoptions is not empty by manually calling Performactionforshortcutitem if(Launchoptions! =Nil) {Uiapplicationshortcutitem*i =[Launchoptions Objectforkey:uiapplicationlaunchoptionsshortcutitemkey]; [Self application:application performactionforshortcutitem:i completionhandler:^(BOOL succeeded) {NSLog (@"launchoptions no null"); }]; returnNO; } returnYES;}
Two. Info.plist
=============================
Reference: HTTP://WWW.JIANSHU.COM/P/74FE6CBC542B
3dtouch-shortcutitem-ios9-xcode7