[英]How do I share .zip file using UIActivityViewController?
我需要通過電子郵件/ iTunes /其他方式(例如消息,AirDrop)共享.zip文件。 我已經可以通過電子郵件和iTunes發送壓縮文件,但是當我嘗試使用UIActivityViewController發送壓縮文件時,它沒有顯示任何文件。
這是代碼:
-(void) sendAllToApp {
NSString *dpath=NSTemporaryDirectory();
NSString *zipfile=[dpath stringByAppendingPathComponent:[NSString stringWithFormat:@"All_Reports_of_Project_%@.zip",project.displayName]];
[SSZipArchive createZipFileAtPath:zipfile withFilesAtPaths:zippedURL];//zipfile is the path that I store zip file data,zippedURL is the paths of files t.
NSData *zipData=[[NSFileManager defaultManager]contentsAtPath:zipFile];
NSURL *url =[NSURL fileURLWithPath:zipfile];
[zipData writeToURL:url atomically:NO];
if(zipData != nil) {
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[url] applicationActivities:nil];
activityViewController.excludedActivityTypes = @[UIActivityTypePrint];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
activityViewController.popoverPresentationController.sourceView = self.navigationController.view;
activityViewController.popoverPresentationController.sourceRect = CGRectMake(self.navigationController.view.bounds.size.width/2, self.navigationController.view.bounds.size.height/4, 0, 0);
}
[self.navigationController presentViewController:activityViewController animated:true completion:nil];
activityViewController.completionWithItemsHandler = ^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
// When completed flag is YES, user performed specific activity
};
[self clearTmpDirectory];
}
else {
[self showError];
[self clearTmpDirectory];
}
}
我將項目都設置為@[url]
和@[zipData]
。
使用URL時,無法使用AirDrop。
使用zip數據時,我在MacBook中得到一個.data文件。 如果將.data文件更改為.zip,它將成為我要共享的正確文件。
那么,如何正確共享.zip文件?
我們有同樣的問題。 對我們有用的唯一解決方法是將.zip轉換為.tar文件,可以使用包含其路徑的NSURL共享該文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.