3dtouch-shortcutitem-ios9-xcode7

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.