我已經在應用程序中創建了shortcutItem
,並且當我在ios 9.2中運行時它工作正常。但是當我打開具有ios 8.1的應用程序時,它會崩潰。爲以前版本的應用程序崩潰創建快捷方式
主題1:EXC_BAD_ACCESS(代碼= 1,地址=爲0x0)
是如何shortcutItem
創建說,如果我創建(launchOption == nil) return YES
後動態shortcutItem
圖標和標題是否手機顯示shortcutItems
然後(?因爲createShortcutItem
不叫它不應該顯示是我的想法。)一旦我打開應用程序打開應用程序打開並儘可能最小化,即使shortcutItems
和圖標沒有在didFinishLaunchingwithoptions
中調用,我將能夠打開shortcutItem
。
日上午在這一行
shortcutItem = [launchOptions objectForKeyedSubscript:UIApplicationLaunchOptionsShortcutItemKey];
,所以我回到if launchOptions == nil
修復毀人在IOS 8.1崩潰。
以下是我在使用快捷方式的應用程序中使用的代碼。它是在我的主應用程序中創建的,所以我稍微修改了一些名稱。
如何處理早期iOS(從8.0)或設備不支持的快捷方式。我希望我的應用程序支持ios8和更高版本。應用程序被使用快捷打開時
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
BOOL shouldPerformAdditionalDelegateHandling = YES;
// Shortcut creation and methods
[[MyAppShortcuts instance] createShortcutItem];
if (launchOptions == nil) {
return shouldPerformAdditionalDelegateHandling;
}
UIApplicationShortcutItem *shortcutItem;
shortcutItem = [launchOptions objectForKeyedSubscript:UIApplicationLaunchOptionsShortcutItemKey];
if (shortcutItem != nil){
// Open app from shortcut
self.rootViewCtrl_.shortcutItem_ = shortcutItem;
[[MyAppShortcuts instance] setMyAppShortcutIs:shortcutItem.type];
[[MyAppShortcuts instance] setAppLaunchedWithShortcut:YES];
// This will block "performActionForShortcutItem:completionHandler" from 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:
方法被稱爲每次。如果我在每次調用的方法內部創建shortcutItems(icon, title and type)
,是否會以任何方式影響打開快捷方式,因爲一次又一次創建項目?
- (void) application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler
{
// Shortcut creation and methods
[ [ MyAppShortcuts instance ] createShortcutItem ];
[[FinAppShortcuts instance] handleShortCut:shortcutItem ];
}
崩潰時的消息究竟是什麼?你爲什麼要調用'objectForKeyedSubscript:'而不是普通的'objectForKey:'? –
崩潰是「線程1:EXC_BAD_ACCESS(代碼= 1,地址= 0x0)」以紅色突出 – Jaff