Any native IOS users give some help?

Monkey Targets Forums/iOS/Any native IOS users give some help?

OvineByDesign(Posted 2017) [#1]
I have a working android app that shares a screenshot from my app and I need todo the same for the IOS version.

Im struggling using UIActivityViewController , that should allow a path to a file and pop up the in built sharing screen ?


#import <UIKit/UIKit.h>
#import <AssetsLibrary/AssetsLibrary.h>

class apptest 
{
public:

	static void share(void)
	{	
		    NSString *URL = @"monkey://internal/pic.bmp"; 
        UIActivityViewController *imagePicker = [[UIActivityViewController alloc] initWithActivityItems:@[@"share", URL] applicationActivities:nil];
        [presentViewController:imagePicker animated:YES completion:NULL];
	}
}





Any help would be appreciated.

/Stu


Ferdi(Posted 2017) [#2]
Hi Stu, I think this is what you want. It is rather messy, lots of comments here and there.

I should just point out that there is an if statement for iphone and ipad. If you just use the iphone code on an ipad, it will cause a reset problem!

Also the ipad version I think that code got deprecated at IOS 8. So you may want to update that part of the code for IOS 9+? If you have an ipad just test it make sure it is all working. I don't have an ipad, so I can't test it.

Anyway hope it helps.

void ShowShare(String title, String text, String screenshot)
{
	String fullPath = BBGame::Game()->PathToFilePath( screenshot );
	//NSLog(@"fullPath = %@", fullPath.ToNSString());

	UIImage * img = [UIImage imageWithContentsOfFile:fullPath.ToNSString()];

	NSArray * objectsToShare = @[text.ToNSString(), img];

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

//UIActivityTypePostToFacebook
//UIActivityTypePostToTwitter
//UIActivityTypePostToWeibo
//UIActivityTypeMessage
//UIActivityTypeMail
//UIActivityTypePrint
//UIActivityTypeCopyToPasteboard
//UIActivityTypeAssignToContact
//UIActivityTypeSaveToCameraRoll
//UIActivityTypeAddToReadingList
//UIActivityTypePostToFlickr
//UIActivityTypePostToVimeo
//UIActivityTypePostToTencentWeibo
//UIActivityTypeAirDrop

	NSArray * excludeActivities = @[UIActivityTypeAirDrop,
									//UIActivityTypePrint,
									//UIActivityTypeAssignToContact,
									//UIActivityTypeSaveToCameraRoll,
									UIActivityTypeAddToReadingList,
									UIActivityTypePostToFlickr,
									UIActivityTypePostToVimeo];

	activityVC.excludedActivityTypes = excludeActivities;

	// Where did you get the appDelegate line from?
	// modules/brl/native/admob.ios.cpp  L56
	BBMonkeyAppDelegate *appDelegate=(BBMonkeyAppDelegate*)[[UIApplication sharedApplication] delegate];
	//[appDelegate->viewController presentViewController:activityVC animated:YES completion:nil];

// If you use just the following line, it will crash on iPad!
//	[appDelegate->viewController presentViewController:activityVC animated:YES completion:^{}];

	//if iPhone
	if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
		[appDelegate->viewController presentViewController:activityVC animated:YES completion:nil];
	}
	//if iPad
	else
	{
		// Change Rect to position Popover
		UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:activityVC];
		[popup presentPopoverFromRect:CGRectMake(appDelegate->viewController.view.frame.size.width/2, appDelegate->viewController.view.frame.size.height/4, 0, 0)inView:appDelegate->viewController.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
	}
	
	//[img autorelease];
}



OvineByDesign(Posted 2017) [#3]
you are a legend Ferdi ! - many thanks. i could see I had to involve the money delegate but couldnt see how !!!!

I'll investigate further on the ipad. I'll post back if I get that working


OvineByDesign(Posted 2017) [#4]
working perfectly on Ipad


Ferdi(Posted 2017) [#5]
Thanks for the update. Good to hear it is working on iPad.

Is it alright if I asked what version of iOS the iPad is running on? Is it iOS 10?