1

I'm building my first game in Unity and I've almost completed it. I want to share a screenshot of my game over scene in multiple social platforms like Facebook, Twitter, E-mail etc. But I'm not able to do this. I don't want to use any plugins.

I want to do like this

enter image description here

Any help would be helpful.

ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
rasel raaz
  • 101
  • 3
  • 7
  • 1
    Why you don't want to use plugins? – N Fard Jul 12 '16 at 08:03
  • I'm not sure about any Plugins till now. @Naeim can you suggest me any plugins which can fulfill my requirements. And if possible share me some resources on Unity sharing.. – rasel raaz Jul 12 '16 at 08:15

2 Answers2

1

Since you mentioned in the comment you can opt for a plugin option, this is the plugin I'm using: https://github.com/ChrisMaire/unity-native-sharing

A little side note is if you import the asset from the.unitypackage file, be sure to replace the post-import file in Assets/Plugins/iOS/ with latest version from master. Latest commit fixes a crash on iPad but it isn't included in the .unitypackage yet.

AVAVT
  • 7,058
  • 2
  • 21
  • 44
  • I've already tried this, but it gives the error of **EntryPointNotFoundException: showSocialSharing**. Is there any other documentation or tutorial for sharing on iOS? Please help me – rasel raaz Jul 12 '16 at 09:59
  • Furthermore, don't forget to add the sharing permission to your plist: https://stackoverflow.com/questions/6029916/how-to-enable-file-sharing-for-my-app – ADB Jul 09 '17 at 18:11
0

Its pretty simple. In your C# code, add the DllImport for your native code and create a simple function that takes in the image path and the text message.

Then in your Assets/Plugins/iOS/ add a class, ex: "ShareHandler.mm"

In that class, have a function that you can call which takes in a path and text. Convert path to image like this:

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

Create NSArray of the items you want to post, here:

NSArray *postItems = @[image, message];

Then add this:

 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];
}

After that, call this function from the extern "C" part of the class:

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

This worked fine for me. Hope this helps.

Do read Unity iOS plugin documentation on how to create Unity iOS plugins. Pretty useful it is! https://docs.unity3d.com/Manual/PluginsForIOS.html