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