【发布时间】:2015-01-15 08:07:12
【问题描述】:
我之前在objective-c。目标 C 中的以下代码运行良好:
在。 h
@property (retain)UIDocumentInteractionController *docController;
在.m
NSString *path = [[NSBundle mainBundle] pathForResource:@"book" ofType:@"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
docController = [UIDocumentInteractionController interactionControllerWithURL:targetURL];
if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"itms-books:"]]) {
[docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
NSLog(@"iBooks installed");
} else {
NSLog(@"iBooks not installed");
}
但现在我正在尝试使用 swift 打开,这是我的 swift 代码:
if let path = NSBundle.mainBundle().pathForResource("book", ofType: "pdf") {
if let targetURL = NSURL.fileURLWithPath(path) {
let docController = UIDocumentInteractionController(URL: targetURL)
let url = NSURL(string:"itms-books:");
if UIApplication.sharedApplication().canOpenURL(url!) {
docController.presentOpenInMenuFromRect(CGRectZero, inView: self.view, animated: true)
println("iBooks is installed")
}else{
println("iBooks is not installed")
}
}
}
但是当我选择 iBooks 打开 pdf 时它会崩溃。谁能帮帮我!
【问题讨论】:
标签: ios objective-c xcode swift