[英]Open Files from mail
我正在努力處理iOS上的文件。 我已經可以將文件類型分配給iOS,並且可以從帶有特殊文件的郵件中啟動應用程序。 我的應用正在啟動,並且正在觸發此方法:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
if([url isFileURL])
{
NSString *fileConts = [[NSString alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@", url] encoding:NSUTF8StringEncoding error:nil];
[self.viewController openFile:fileConts];
fileConts = nil;
}
return YES;
}
openFile:(NSString)
方法在viewController中聲明,並設置textView的值(目前)。 此方法工作正常。 我通過[self.viewController openFile:@"test"];
測試了它[self.viewController openFile:@"test"];
。
但是,當我的應用程序啟動並附加了文件時,textView保持為空。 似乎它沒有采用字符串值或它無法讀取字符串值。
僅當應用程序已在后台運行時,才會調用handleOpenURL。
為了確保正確分發傳入文件,您還需要在應用啟動時對其進行檢查:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *url = (NSURL *)[launchOptions valueForKey:UIApplicationLaunchOptionsURLKey];
// Process url here
}
最好同時從handleOpenURL和didFinishLaunchingWithOptions中調用1個URL調度程序。
我可以解決我的問題。 我的錯誤是initWithContentsOfFile:(NSString *)
我使用NSString *fileConts = [[NSString alloc] initWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&error];
更新了代碼NSString *fileConts = [[NSString alloc] initWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&error];
現在我很高興! 感謝幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.