2012-08-17 103 views
1

我在执行 - (BOOL)应用程序时遇到问题:openURL和使用UIDocumentInteractionController将PDF文件从应用程序导出到另一个应用程序。application:openURL not triggered

(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)问题: - 当我选择目标应用程序(从“打开在”列表)中,从源应用程序模拟器切换到目标应用程序还行,但看起来像应用:OpenURL方法不被调用,因为标签保持为初始状态(没有文件被导入),并且没有警报视图出现。

请告诉我这里可能有什么问题?

在此先感谢。

+0

已经想通了。在将文件URL传递给UIDocumentInteractionController时,我没有包含完整路径,因此,在使用无效URL触发时,application:openURL失败。 – 2012-08-17 15:48:01

回答

-1

只是想标记我的问题为答案,因为我已经找到了故障。

更新:这是我的错,当启动UIDocumentInteractionController对象时不包括完整的文件路径。

+0

你不介意分享吗? – Oleg 2013-06-21 08:49:48

+0

@Oleg:我几乎在一年前发布了答案:“当启动UIDocumentInteractionController对象时,没有包含完整文件路径是我的错。”最近我刚刚通过这个问题,看到它仍然打开,所以我简单地将它标记为已回答,以便专家不必花费宝贵的时间来查看它:)。 – 2013-06-21 19:38:38

0

我使用这两个方法进行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]; 
} 
+0

当启动UIDocumentInteractionController对象时,不包括完整文件路径是我的错。不管怎么说,还是要谢谢你。 – 2012-08-17 15:49:36

+0

@Duy Pham,好的。快乐编码。 – Guru 2012-08-17 15:53:34