【问题标题】:unity game screenshot share in multiple social platform in iosunity游戏截图分享到ios多个社交平台
【发布时间】:2016-11-14 08:34:53
【问题描述】:

我正在 Unity 中构建我的第一个游戏,并且我几乎完成了它。我想在 Facebook、Twitter、E-mail 等多个社交平台上分享我的游戏场景截图。但我无法做到这一点。我不想使用任何插件。

我想这样做

任何帮助都会有所帮助。

【问题讨论】:

  • 为什么不想使用插件?
  • 直到现在我还不确定是否有任何插件。 @Naeim 你能建议我任何可以满足我要求的插件吗?如果可能的话,请与我分享一些关于 Unity 共享的资源..

标签: ios facebook twitter unity3d share


【解决方案1】:

由于您在评论中提到您可以选择插件选项,这是我正在使用的插件:https://github.com/ChrisMaire/unity-native-sharing

一个小提示是,如果您从 .unitypackage 文件导入资产,请务必将 Assets/Plugins/iOS/ 中的导入后文件替换为 master 的最新版本。最新提交修复了 iPad 上的崩溃,但它尚未包含在 .unitypackage 中。

【讨论】:

  • 我已经尝试过了,但是它给出了 EntryPointNotFoundException: showSocialSharing 的错误。是否有任何其他文档或教程可以在 iOS 上共享?请帮帮我
  • 此外,不要忘记将共享权限添加到您的 plist:stackoverflow.com/questions/6029916/…
【解决方案2】:

它非常简单。在您的 C# 代码中,为您的本机代码添加 DllImport,并创建一个简单的函数来接收图像路径和文本消息。

然后在你的 Assets/Plugins/iOS/ 添加一个类,例如:“ShareHandler.mm”

在那个类中,有一个你可以调用的函数,它接受路径和文本。像这样将路径转换为图像:

NSString *imagePath = [NSString stringWithUTF8String:path];
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];

在此处创建要发布的项目的 NSArray:

NSArray *postItems = @[image, message];

然后添加这个:

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

if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && [activityVc respondsToSelector:@selector(popoverPresentationController)] ) {

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

    [popup presentPopoverFromRect:
        CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/4, 0, 0)
        inView:[UIApplication sharedApplication].keyWindow.rootViewController.view
        permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
} else {
    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:activityVc animated:YES completion:nil];
}

之后,从类的 extern "C" 部分调用此函数:

extern "C"{
void shareImageWithTextOnIOS(const char * path, const char * message){
    ImageShareForiOS *vc = [[ImageShareForiOS alloc] init];
    [vc shareMethod:path Message:message];
}

这对我来说很好。希望这会有所帮助。

请阅读 Unity iOS 插件文档以了解如何创建 Unity iOS 插件。它非常有用! https://docs.unity3d.com/Manual/PluginsForIOS.html

【讨论】:

    猜你喜欢
    • 2015-07-15
    • 1970-01-01
    • 1970-01-01
    • 2015-06-22
    • 1970-01-01
    • 1970-01-01
    • 2016-07-22
    • 2012-10-18
    • 1970-01-01
    相关资源
    最近更新 更多