Advertisement
Guest User

Untitled

a guest
May 1st, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. //
  2. // ViewController.m
  3.  
  4.  
  5. @implementation ViewController : UIViewController
  6.  
  7. -(void) shareMethod: (const char *) path Message : (const char *) shareMessage
  8. {
  9. NSString *imagePath = [NSString stringWithUTF8String:path];
  10.  
  11. // UIImage *image = [UIImage imageNamed:imagePath];
  12. UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
  13. NSString *message = [NSString stringWithUTF8String:shareMessage];
  14. NSArray *postItems = @[message,image];
  15.  
  16. UIActivityViewController *activityVc = [[UIActivityViewController alloc]initWithActivityItems:postItems applicationActivities:nil];
  17.  
  18. if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && [activityVc respondsToSelector:@selector(popoverPresentationController)] ) {
  19.  
  20. UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:activityVc];
  21.  
  22. [popup presentPopoverFromRect:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/4, 0, 0)
  23. inView:[UIApplication sharedApplication].keyWindow.rootViewController.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  24. }
  25. else
  26. [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:activityVc animated:YES completion:nil];
  27. [activityVc release];
  28. }
  29. -(void) shareOnlyTextMethod: (const char *) shareMessage
  30. {
  31.  
  32. NSString *message = [NSString stringWithUTF8String:shareMessage];
  33. NSArray *postItems = @[message];
  34.  
  35. UIActivityViewController *activityVc = [[UIActivityViewController alloc] initWithActivityItems:postItems applicationActivities:nil];
  36.  
  37.  
  38. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && [activityVc respondsToSelector:@selector(popoverPresentationController)] ) {
  39.  
  40. UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:activityVc];
  41.  
  42. [popup presentPopoverFromRect:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/4, 0, 0)
  43. inView:[UIApplication sharedApplication].keyWindow.rootViewController.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  44. }
  45. else
  46. [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:activityVc animated:YES completion:nil];
  47. [activityVc release];
  48. }
  49.  
  50. @end
  51.  
  52.  
  53.  
  54. extern "C"{
  55. void _TAG_ShareTextWithImage(const char * path, const char * message){
  56. ViewController *vc = [[ViewController alloc] init];
  57. [vc shareMethod:path Message:message];
  58. [vc release];
  59. }
  60. }
  61. extern "C"{
  62. void _TAG_ShareSimpleText(const char * message){
  63. ViewController *vc = [[ViewController alloc] init];
  64. [vc shareOnlyTextMethod: message];
  65. [vc release];
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement