Skip to content

Instantly share code, notes, and snippets.

@Aaron8052
Last active February 22, 2023 04:31
Show Gist options
  • Save Aaron8052/d71955667bf929cfa5450e2e38264c1d to your computer and use it in GitHub Desktop.
Save Aaron8052/d71955667bf929cfa5450e2e38264c1d to your computer and use it in GitHub Desktop.
【Objective-C】Unity调用iOS分享界面
  • filePath:分享图片的本地路径

  • URL:用户点击分享内容时跳转的页面

  • 需要为iPad单独设置分享界面的弹窗位置以及大小,否则出错

+(void)shareMsg:(NSString *)message addUrl:(NSString *)url imgPath:(NSString *)filePath
{
NSMutableArray *items = [NSMutableArray new];
[items addObject:message];
[items addObject:[NSURL URLWithString:url]];
UIImage *image = [UIImage imageWithContentsOfFile:filePath];
if(image != nil)
[items addObject:image];
UIActivityViewController *activity = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
activity.popoverPresentationController.sourceView = activity.view;
activity.popoverPresentationController.sourceRect = CGRectMake( UnityGetGLViewController().view.frame.size.width / 2, UnityGetGLViewController().view.frame.size.height / 2, 1, 1 );
}
[UnityGetGLViewController() presentViewController:activity animated:YES completion:nil];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment