美文网首页
UIActivityViewController分享文件

UIActivityViewController分享文件

作者: fordG | 来源:发表于2019-04-01 15:11 被阅读0次
#import

#import

@interfaceShareManager :NSObject

+ (void)shareFile: (NSString *)filePath handler: (UIActivityViewControllerCompletionWithItemsHandler)handler;

@end
#import "ShareManager.h"

@implementation ShareManager

+ (void)shareFile: (NSString *)filePath handler: (UIActivityViewControllerCompletionWithItemsHandler)handler{



    //文件链接

    NSURL*urlToShare = [NSURLfileURLWithPath:filePath];

    //文件二进制数据

    NSData*data = [NSDatadataWithContentsOfFile:filePath];

    NSArray*activityItems =@[data, urlToShare];

    UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil];

    //不出现在活动项目

    activityVC.excludedActivityTypes = @[UIActivityTypePrint, UIActivityTypeCopyToPasteboard,UIActivityTypeAssignToContact,UIActivityTypeSaveToCameraRoll];

    [[UIApplication sharedApplication].delegate.window.rootViewController presentViewController:activityVC animated:YES completion:nil];

    // 分享之后的回调

    activityVC.completionWithItemsHandler= ^(UIActivityType  _NullableactivityType,BOOLcompleted,NSArray*_NullablereturnedItems,NSError*_NullableactivityError) {

        handler(activityType, completed, returnedItems, activityError);

    };

}

iOS 在系统分享列表中加入自己的应用
iOS如何从微信中跳转APP

相关文章

网友评论

      本文标题:UIActivityViewController分享文件

      本文链接:https://www.haomeiwen.com/subject/yzevbqtx.html