pad开发中调用系统原生社会化分享

我们需要调用系统UIActivityViewController类

// 要分享的图片

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

// 要分享的文字

NSString *str=@"Image form My app";

// 将要分享的元素放到一个数组中

NSArray *postItems=@[str,image];

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

UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:activityVC];

// 在展现 activityVC 时,必须根据当前的设备类型,使用适当的方法。在iPad上,必须通过popover来展现view controller。在iPhone和iPodtouch上,必须以模态的方式展现。

if ([[UIDevice currentDevice].model isEqualToString:@"iPad"]) {

UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:activityVC];

[popup presentPopoverFromRect:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/4, 0, 0) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

} else {

[self presentViewController:activityVC animated:YES completion:nil];

}


原文地址:www.jianshu.com/p/9cbef2d1be21

关于其他的分享参照iOS 社会化分享方案总结

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1、禁止手机睡眠[UIApplication sharedApplication].idleTimerDisabl...
    DingGa阅读 1,160评论 1 6
  • 1、设置UILabel行间距 NSMutableAttributedString* attrString = [[...
    FF_911阅读 1,454评论 0 3
  • //设置尺寸为屏幕尺寸的时候self.window = [[UIWindow alloc] initWithFra...
    LuckTime阅读 865评论 0 0
  • iphone开发笔记 退回输入键盘 - (BOOL) textFieldShouldReturn:(id)text...
    爱易寒曲易散阅读 644评论 0 1
  • 短短十五天,在亲眼见证了无数项目的奖牌突破后,宁一终于懂得了如何享受比赛。 自奥运会第一个比赛日到今天,中国队在很...
    王家人宁阅读 194评论 0 0