UIActivityViewController分享文件

2019-04-01  本文已影响0人  fordG
#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

上一篇 下一篇

猜你喜欢

热点阅读