Ios 3D触摸快捷菜单未重定向到视图控制器
我正在使用objective-c创建3D触摸快捷菜单。我遵循了这个示例,了解了如何实现它,并查看了有关如何实现它的swift教程,但仍然存在一些问题 但是,只要点击其中一个项目,快捷菜单就会完美地显示出来,它会将我带到应用程序的主页,而不是我指定的视图 下面是我的应用程序代理中使用的代码Ios 3D触摸快捷菜单未重定向到视图控制器,ios,objective-c,3dtouch,Ios,Objective C,3dtouch,我正在使用objective-c创建3D触摸快捷菜单。我遵循了这个示例,了解了如何实现它,并查看了有关如何实现它的swift教程,但仍然存在一些问题 但是,只要点击其中一个项目,快捷菜单就会完美地显示出来,它会将我带到应用程序的主页,而不是我指定的视图 下面是我的应用程序代理中使用的代码 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOpti
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Check API availiability
// UIApplicationShortcutItem is available in iOS 9 or later.
if([[UIApplicationShortcutItem class] respondsToSelector:@selector(new)]){
[self configDynamicShortcutItems];
// If a shortcut was launched, display its information and take the appropriate action
UIApplicationShortcutItem *shortcutItem = [launchOptions objectForKeyedSubscript:UIApplicationLaunchOptionsShortcutItemKey];
if(shortcutItem)
{
// When the app launch at first time, this block can not called.
[self handleShortCutItem:shortcutItem];
// This will block "performActionForShortcutItem:completionHandler" from being called.
shouldPerformAdditionalDelegateHandling = NO;
}
}
return shouldPerformAdditionalDelegateHandling;
- (void)configDynamicShortcutItems {
// config image shortcut items
// if you want to use custom image in app bundles, use iconWithTemplateImageName method
UIApplicationShortcutIcon *shortcutSearchIcon = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeBookmark];
UIApplicationShortcutIcon *shortcutFavoriteIcon = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeBookmark];
UIApplicationShortcutItem *shortcutSearch = [[UIApplicationShortcutItem alloc]
initWithType:@"com.sarangbang.QuickAction.Search"
localizedTitle:@"Events"
localizedSubtitle:nil
icon:shortcutSearchIcon
userInfo:nil];
UIApplicationShortcutItem *shortcutFavorite = [[UIApplicationShortcutItem alloc]
initWithType:@"com.sarangbang.QuickAction.Favorite"
localizedTitle:@"Latest News"
localizedSubtitle:nil
icon:shortcutFavoriteIcon
userInfo:nil];
// add all items to an array
NSArray *items = @[shortcutSearch, shortcutFavorite];
// add the array to our app
[UIApplication sharedApplication].shortcutItems = items;
}
- (BOOL)handleShortCutItem : (UIApplicationShortcutItem *)shortcutItem{
BOOL handled = NO;
NSString *bundleId = [NSBundle mainBundle].bundleIdentifier;
NSString *shortcutSearch = [NSString stringWithFormat:@"%@.Search", bundleId];
NSString *shortcutFavorite = [NSString stringWithFormat:@"%@.Favorite", bundleId];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
if ([shortcutItem.type isEqualToString:shortcutSearch]) {
handled = YES;
EventsViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"EventsViewController"];
UINavigationController *navController;
[navController pushViewController:vc animated:YES];
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];
}
else if ([shortcutItem.type isEqualToString:shortcutFavorite]) {
handled = YES;
NewsViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"NewsViewController"];
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];
}
return handled;
}
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler{
BOOL handledShortCutItem = [self handleShortCutItem:shortcutItem];
completionHandler(handledShortCutItem);
}
调试的结果是什么?程序是否进入正确的if?
vc
在调用instantialeviewcontrollerwhithidentifier
后是否持有正确的视图控制器?好的,我最终找到了答案。事实证明,在我的initWithType
中,捆绑包标识符是错误的。它应该是com.yoursite.yourapp.value