Skip to content

Instantly share code, notes, and snippets.

@wertgit
Last active May 1, 2017 06:09
Show Gist options
  • Save wertgit/5c00a39cac51ccf55ece5f43bf1fbed7 to your computer and use it in GitHub Desktop.
Save wertgit/5c00a39cac51ccf55ece5f43bf1fbed7 to your computer and use it in GitHub Desktop.
//
// ViewController.m
@implementation ViewController : UIViewController
-(void) shareMethod: (const char *) path Message : (const char *) shareMessage
{
NSString *imagePath = [NSString stringWithUTF8String:path];
// UIImage *image = [UIImage imageNamed:imagePath];
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
NSString *message = [NSString stringWithUTF8String:shareMessage];
NSArray *postItems = @[message,image];
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];
[activityVc release];
}
-(void) shareOnlyTextMethod: (const char *) shareMessage
{
NSString *message = [NSString stringWithUTF8String:shareMessage];
NSArray *postItems = @[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];
[activityVc release];
}
@end
extern "C"{
void _TAG_ShareTextWithImage(const char * path, const char * message){
ViewController *vc = [[ViewController alloc] init];
[vc shareMethod:path Message:message];
[vc release];
}
}
extern "C"{
void _TAG_ShareSimpleText(const char * message){
ViewController *vc = [[ViewController alloc] init];
[vc shareOnlyTextMethod: message];
[vc release];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment