ios - Creating shortcut for the app crashes on previous version -


i've created shortcutitem in app , when run in ios 9.2 works fine. when open app has ios 8.1 crashes.

thread 1:exc_bad_access (code=1, address=0x0)

how shortcutitem created if create shortcutitem icon , title dynamically after (launchoption == nil) return yes phone shows shortcutitems then?(because createshortcutitem not called should not show think.) able open shortcutitem once opened app opened , minimized though shortcutitems , icons not called in didfinishlaunchingwithoptions.

am getting crashes in ios 8.1 @ line

shortcutitem = [launchoptions objectforkeyedsubscript:uiapplicationlaunchoptionsshortcutitemkey]; 

so returning if launchoptions == nil fix crash.

below code using in app using shortcut. created in main app i've modified names little bit example.

how handle shortcut not supported on ios ( 8.0) or devices. want app support both ios8 , greater versions.

- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions {   // override point customization after application launch.   bool shouldperformadditionaldelegatehandling = yes;    // shortcut creation , methods   [[myappshortcuts instance] createshortcutitem];    if (launchoptions == nil) {     return shouldperformadditionaldelegatehandling;   }    uiapplicationshortcutitem *shortcutitem;   shortcutitem = [launchoptions objectforkeyedsubscript:uiapplicationlaunchoptionsshortcutitemkey];    if ( shortcutitem != nil ){     // open app shortcut     self.rootviewctrl_.shortcutitem_ = shortcutitem;      [[myappshortcuts instance] setmyappshortcutis:shortcutitem.type];     [[myappshortcuts instance] setapplaunchedwithshortcut:yes];      // block "performactionforshortcutitem:completionhandler" being called.     shouldperformadditionaldelegatehandling = no;   }   return shouldperformadditionaldelegatehandling; }   - (void) createshortcutitem {   uiapplicationshortcuticon* firsticon = [uiapplicationshortcuticon iconwithtemplateimagename:@"shortcutfirstitem"];   uiapplicationshortcutitem* firstitem;   firstitem = [[uiapplicationshortcutitem alloc]initwithtype: firstitemtype                                                  localizedtitle: nslocalizedstring(@"first item", nil)                                               localizedsubtitle: nil                                                            icon: firsticon                                                        userinfo: nil];   //..... creating 2nd 3rd 4th item   [uiapplication sharedapplication].shortcutitems = @[firstitem, seconditem, thirditem, fourthitem]; } 

application:performactionforshortcutitem: method called everytime when app opened using shortcut. if create shortcutitems(icon, title , type) inside method calls everytime, affect opening shortcut in way because creating items again , again?

- (void) application:(uiapplication *)application performactionforshortcutitem:(uiapplicationshortcutitem *)shortcutitem completionhandler:(void (^)(bool))completionhandler {     // shortcut creation , methods     [ [ myappshortcuts instance ] createshortcutitem ];     [[finappshortcuts instance] handleshortcut:shortcutitem ];      } 

you should place logic regarding shortcut items after checking if it's available (ios 9.1 onwards). don't think launchoptions nil instances it's not invoked tapping shortcut.

- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions {     // override point customization after application launch.     bool shouldperformadditionaldelegatehandling = yes;      //checks if user shortcut items. available in ios 9.1 onwards     if ([uiapplicationshortcutitem class]){          // shortcut creation , methods         [[myappshortcuts instance] createshortcutitem];          if (launchoptions[uiapplicationlaunchoptionsshortcutitemkey]){             // open app shortcut             self.rootviewctrl_.shortcutitem_ = shortcutitem;             [[myappshortcuts instance] setmyappshortcutis:shortcutitem.type];             [[myappshortcuts instance] setapplaunchedwithshortcut:yes];             // block "performactionforshortcutitem:completionhandler" being called.             shouldperformadditionaldelegatehandling = no;         }      }     return shouldperformadditionaldelegatehandling; } 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -