0
當我以快速操作啓動應用程序時,我很難弄清楚如何讓我的快速操作正常工作。通過快速操作處理應用程序啓動的正確方法
我快行動工作,但是,如果應用程序在後臺與行動迅速重新啓動。
當我嘗試從行動迅速直啓動應用程序,該應用程序會打開,如果它是隻需按應用程序圖標啓動(即它什麼都不做)。
這裏是我的應用程序代表的一些代碼。
在didFinishLaunchingWithOptions:
UIApplicationShortcutItem *shortcut = launchOptions[UIApplicationLaunchOptionsShortcutItemKey];
if(shortcut != nil){
performShortcutDelegate = NO;
[self performQuickAction: shortcut fromLaunch:YES];
}
調用的方法:
-(BOOL) performQuickAction: (UIApplicationShortcutItem *)shortcutItem fromLaunch:(BOOL)launchedFromInactive {
NSMutableArray *meetings = [self.fetchedResultController.fetchedObjects mutableCopy];
[meetings removeObjectAtIndex:0];
unsigned long count = meetings.count;
BOOL quickActionHandled = NO;
if(count > 0){
MainViewController *mainVC = (MainViewController *)self.window.rootViewController;
if(launchedFromInactive){
mainVC.shortcut = shortcutItem;
}
else{
UINavigationController *childNav;
MeetingViewController *meetingVC;
for(int i = 0; i < mainVC.childViewControllers.count; i++){
if([mainVC.childViewControllers[i] isKindOfClass: [UINavigationController class]]){
childNav = mainVC.childViewControllers[i];
meetingVC = childNav.childViewControllers[0];
break;
}
}
self.shortcutDelegate = meetingVC;
if ([shortcutItem.type isEqual: @"Meeting"]){
NSNumber *index = [shortcutItem.userInfo objectForKey:@"Index"];
[self.shortcutDelegate switchToCorrectPageWithIndex: index launchedFromInactive:NO];
quickActionHandled = YES;
}
}
}
需要被執行的唯一動作是,我的頁面視圖控制器(其嵌入在meetingVC內)應關於所選擇的快捷方式切換到某個頁面。
是什麼原因導致的快捷使用它來啓動,而不是從後臺重新打開應用程序時,不要做任何事情,任何想法?
我敲了一次前這個問題,我再有同樣的問題,我想這是因爲具有快速行動啓動應用程序時,根視圖控制器尚未建立,所以你不能調用方法在上面。可悲的是我沒有辦法解決。 – SimonBarker
我找到了我的程序解決方案!希望它適用於其他人正在尋找一種方法來做到這一點。 – iOShepherd