クイックアクションでアプリケーションを起動すると、クイックアクションの仕組みを理解するのに苦労しています。クイックアクションでアプリケーションの起動を処理する正しい方法
ただし、アプリがバックグラウンドにあり、クイックアクションで再起動された場合、クイックアクションは機能します。
クイックアクションからアプリをすぐに起動しようとすると、単にアプリアイコンをタップするだけで起動されたようにアプリが開きます(つまり何もしません)。
ここに私のApp Delegateのコードがあります。
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内部に埋め込まれている)私のページビューコントローラがなければならないということであるdidFinishLaunchingWithOptionsで
選択されたショートカットに対して特定のページに切り替えます。
バックグラウンドからアプリを再オープンするのではなく、ショートカットを使用して起動すると何が起こらないかについてのアイデアはありますか?
前回同じ問題が再発しましたが、同じ問題が再発しています。これは、クイックアクションでアプリを起動すると、ルートビューコントローラがまだ作成されていないため、メソッドを呼び出せないためですその上に。私は悲しいことに、解決策はありません。 – SimonBarker
私のプログラムのための解決策が見つかりました!うまくいけば、これを行う方法を探している他の人にも当てはまります。 – iOShepherd