我在应用程序中创建了shortcutItem
,当我在ios 9.2中运行时,它运行正常。但是,当我打开具有ios 8.1的应用程序时,它会崩溃。
线程1:EXC_BAD_ACCESS(代码= 1,地址= 0x0)
shortcutItem
的创建方式如果我在shortcutItem
之后动态创建(launchOption == nil) return YES
图标和标题,如果手机显示shortcutItems
那么?(因为createShortcutItem
没有被称为它不应该显示我的想法。)一旦我打开应用程序打开并最小化我将能够打开shortcutItem
即使shortcutItems
和图标未在{{1 }}
我在此行的ios 8.1中崩溃了
didFinishLaunchingwithoptions
所以我正在返回shortcutItem = [launchOptions objectForKeyedSubscript:UIApplicationLaunchOptionsShortcutItemKey];
来修复崩溃。
以下是我在我的应用中使用快捷方式的代码。它是在我的主应用程序中创建的,所以我稍微修改了一些名称作为例子。
如何处理早期iOS(从8.0)或设备不支持的快捷方式。我希望我的应用程序支持ios8和更高版本。
if launchOptions == nil
每次使用快捷方式打开应用程序时都会调用 - (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)
答案 0 :(得分:2)
在检查快捷项是否可用(iOS 9.1以后)之后,您应该放置关于快捷项的所有逻辑。对于没有通过点击快捷方式调用它的实例,我认为launchOptions不是nil。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
BOOL shouldPerformAdditionalDelegateHandling = YES;
//checks if you could user shortcut items. only available in iOS 9.1 onwards
if ([UIApplicationShortcutItem class]){
// Shortcut creation and methods
[[MyAppShortcuts instance] createShortcutItem];
if (launchOptions[UIApplicationLaunchOptionsShortcutItemKey]){
// 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;
}