【发布时间】:2015-06-08 07:18:27
【问题描述】:
实际上,我正在关注this 文档,以通过 url 方案从我的应用程序在 iOS MS_EXCEL 应用程序中打开我的 excel 表。 通过使用它的文档,我成功打开了 EXCEL 应用程序。但我完全无法打开我的 excel 表。每次 EXCEL 应用程序都会在此图像中显示错误
我正在将我保存的文件 url 传递给 Excel 应用程序。我已经通过 iExplorer 检查了保存的文件路径。该文件已完美打开。但是在 Excel 应用中,它真的让我很头疼。
请帮我看看我在哪里犯了错误。 这是我的代码 sn-p
static NSString * encodeByAddingPercentEscapes(NSString *input) {
NSString *encodedValue =
(NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(
kCFAllocatorDefault,
(CFStringRef)input,
NULL,
(CFStringRef)@"!*'();:@&=+$,/?%#[]",
kCFStringEncodingUTF8));
return encodedValue;
}
-(NSURL*)excelUrlStringForFile:(NSString*)urlFile WithContext:(NSString*)strContext
{
NSURL *result =[NSURL URLWithString:[[NSString stringWithFormat:@"ms-excel:ofe|u|%@|p|%@|c|%@",encodeByAddingPercentEscapes(urlFile),urlScheme,strContext] stringByAddingPercentEscapesUsingEncoding:4]];
return result;
}
如果我没有使用“NSUTF8StringEncoding 编码字符串”
上面的NSURL 对象result 设置为nil。所以我必须使用编码。
NSURL *openExcelURL = [self excelUrlStringForFile:filePath WithContext:str_fileName];
if([[UIApplication sharedApplication] canOpenURL:openExcelURL])
{
[[UIApplication sharedApplication] openURL:openExcelURL];
}
【问题讨论】:
-
Naaaah.. 不走运.. 我有另一种临时方法.. UIDocumentIntractionController
-
这是我从this post的cmets中读到的:
Due to the security model of iOS applications, it’s not possible to directly open a local file from an application to another application.
标签: ios excel url-scheme