iOS 在系统分享列表中加入自己的应用

iOS 在系统分享列表中加入自己的应用,第1张

这里需要将其他应用的文件分享到我们自己的应用,让我们的应用出现在任何文件分享的情况下

效果如图:

分享过来的文件,会存在沙盒下的Documents/Inbox文件夹下。

可以在AppDelegate中重写openURL方法

这里需要注意NSURL转NSString,需要用UTF-8处理下。

这样就可以获取其他App的文件了

调用下面的方法即可实现系统分享功能

//分享

- (IBAction)RespostClick_Action:(id)sender {

UIImage* image = [UIImage imageNamed:@"icon_share.png"]

NSString *text = @"I found an Awesome application software! InstaDown"

//https://itunes.apple.com/us/app/id1260302654?l=zh&ls=1&mt=8

NSURL *urlToShare = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/us/app/id%@?l=zh&ls=1&mt=8",[HHLADSManager getValueFromjsondata:@"appid"]]]

NSArray *activityItems = @[text,image,urlToShare]

UIActivityViewController *avc = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil]

[self presentViewController:avc animated:TRUE completion:nil]

// 选中分享类型

[avc setCompletionWithItemsHandler:^(NSString * __nullable activityType, BOOL completed, NSArray * __nullable returnedItems, NSError * __nullable activityError){

// 显示选中的分享类型

NSLog(@"act type %@",activityType)

if (completed) {

NSLog(@"ok")

}else {

NSLog(@"no ok")

}

}]

UIPopoverPresentationController *popover = avc.popoverPresentationController

if (popover) {

popover.sourceView = self.view

popover.sourceRect = self.view.bounds

popover.permittedArrowDirections = UIPopoverArrowDirectionUp

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11600696.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-17
下一篇2023-05-17

发表评论

登录后才能评论

评论列表(0条)

    保存