概述
NSData *date = [NSData dataWithContentsOfURL:[NSURL URLWithString:[data objectForKey:@"imgurl"]]];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject];
NSFileManager *fileManger = [NSFileManager defaultManager];
NSString*testDirectory = [documentsDirectorystringByAppendingString:@"/"];
// 创建目录
[fileMangercreateDirectoryAtPath:testDirectory withIntermediateDirectories:YES attributes:nil error:nil];
// 创建文件
NSString *name =[NSString stringWithFormat:@"%@.pdf",[data objectForKey:@"filename"]];
NSString*testPath = [testDirectorystringByAppendingPathComponent:name];
// 写入文件
[fileMangercreateFileAtPath:testPathcontents:dateattributes:nil];
NSURL* file = [NSURLfileURLWithPath:testPath];
UIActivityViewController * activity = [[UIActivityViewController alloc]initWithActivityItems:@[file]
applicationActivities:nil];
activity.completionWithItemsHandler = ^(UIActivityType _Nullable activityType,
BOOLcompleted,
NSArray*_NullablereturnedItems,
NSError*_NullableactivityError) {
if(completed ==YES) {
if ([activityType isEqualToString:@"com.apple.CloudDocsUI.AddToiCloudDrive"]) {
[SVProgressHUDshowSuccessWithStatus:@"保存成功,请到系统“文件”中查看"duration:5];
}
else if ([activityType isEqualToString:@"com.tencent.xin.sharetimeline"]||[activityType isEqualToString:@"com.tencent.mqq.ShareExtension"]) {
[SVProgressHUDshowSuccessWithStatus:@"分享成功"];
}else{
[SVProgressHUDshowSuccessWithStatus:@"成功"];
}
}
NSLog(@"activityType: %@,n completed: %d,n returnedItems:%@,n activityError:%@",activityType,completed,returnedItems,activityError);
};
[[UIApplication sharedApplication].keyWindow.rootViewController presentModalViewController:activity animated:NO];
最后
以上就是坚强蜻蜓为你收集整理的ios 上传pdf文件到服务器,iOS使用原生分享做PDF存储及分享的全部内容,希望文章能够帮你解决ios 上传pdf文件到服务器,iOS使用原生分享做PDF存储及分享所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复