我在执行 - (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方法不被调用,因为标签保持为初始状态(没有文件被导入),并且没有警报视图出现。
请告诉我这里可能有什么问题?
在此先感谢。
已经想通了。在将文件URL传递给UIDocumentInteractionController时,我没有包含完整路径,因此,在使用无效URL触发时,application:openURL失败。 – 2012-08-17 15:48:01