1

- (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 メソッドが呼び出されないように見えます。がインポートされます)、アラート ビューは表示されません。

ここで何が間違っているのか教えてください。

前もって感謝します。

4

2 に答える 2

0

これらの 2 つの方法を使用して Facebook と統合し、openURL を処理しました...正常に動作しています。

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    return [ [[HIFacebookConnect sharedGameObject] facebook] handleOpenURL:url];
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    return [[[HIFacebookConnect sharedGameObject] facebook] handleOpenURL:url];
}
于 2012-08-17T15:08:49.977 に答える
-1

私はすでにグリッチを見つけたので、私の質問を回答済みとしてマークしたいだけです。

更新: UIDocumentInteractionController オブジェクトを開始するときに完全なファイル パスを含めなかったのは私のせいでした。

于 2013-06-21T08:44:47.923 に答える