- (BOOL)application:openURL の実装と、アプリケーションから別のアプリケーションに PDF ファイルをエクスポートするための UIDocumentInteractionController の使用に問題があります。
(1) 対象アプリは取り込んだPDFファイルのURLを(ラベルに)表示するだけです。
AppDelegate.m のコードは次のとおりです。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithText:@"No file is imported."];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication: (NSString *)sourceApplication annotation:(id)annotation
{
if (url != nil)
{
[self.viewController handleOpenURL:url];
return YES;
}
else
{
[self.viewController handleOpenURL:[NSURL fileURLWithPath:@"AppDelegate.h"]];
return NO;
}
}
メソッド「handleOpenURL」は、URL を取得してビュー コントローラーにラベルを付け、アラートを表示します。
- (void)handleOpenURL:(NSURL *)fileURL
{
_text = [fileURL absoluteString];
self.lblText.text = _text;
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:_text delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
[alert show];
}
(2) ソース アプリケーションでは、単に UIDocumentInteractionController を使用して「開く」オプションを一覧表示します (ターゲット アプリケーションが一覧に表示されます)。
コードは次のとおりです。
_docInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:attachmentFile]];
_docInteractionController.delegate = self;
_docInteractionController.UTI = [_extensionUTIs objectForKey:[[attachmentFile pathExtension] lowercaseString]];
BOOL opened = [_docInteractionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:NO];
(3) 問題: - (「開く」リストから) ターゲット アプリケーションを選択すると、シミュレーターはソース アプリケーションからターゲット アプリケーションに正常に切り替わりますが、ラベルが初期のまま (ファイルなし) のままであるため、application:openURL メソッドが呼び出されないように見えます。がインポートされます)、アラート ビューは表示されません。
ここで何が間違っているのか教えてください。
前もって感謝します。