Advertisement
Guest User

Untitled

a guest
Apr 25th, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. #import <UIKit/UIKit.h>
  2.  
  3. @interface ActivityViewCustomActivity : UIActivity
  4.  
  5. @end
  6.  
  7. #import "ActivityViewCustomActivity.h"
  8.  
  9. @implementation ActivityViewCustomActivity
  10.  
  11. - (NSString *)activityType
  12. {
  13. return @"yourappname.Review.App";
  14. }
  15.  
  16. - (NSString *)activityTitle
  17. {
  18. return @"Review App";
  19. }
  20.  
  21. - (UIImage *)activityImage
  22. {
  23. // Note: These images need to have a transparent background and I recommend these sizes:
  24. // iPadShare@2x should be 126 px, iPadShare should be 53 px, iPhoneShare@2x should be 100
  25. // px, and iPhoneShare should be 50 px. I found these sizes to work for what I was making.
  26.  
  27. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  28. {
  29. return [UIImage imageNamed:@"iPadShare.png"];
  30. }
  31. else
  32. {
  33. return [UIImage imageNamed:@"iPhoneShare.png"];
  34. }
  35. }
  36.  
  37. - (BOOL)canPerformWithActivityItems:(NSArray *)activityItems
  38. {
  39. NSLog(@"%s", __FUNCTION__);
  40. return YES;
  41. }
  42.  
  43. - (void)prepareWithActivityItems:(NSArray *)activityItems
  44. {
  45. NSLog(@"%s",__FUNCTION__);
  46. }
  47.  
  48. - (UIViewController *)activityViewController
  49. {
  50. NSLog(@"%s",__FUNCTION__);
  51. return nil;
  52. }
  53.  
  54. - (void)performActivity
  55. {
  56. // This is where you can do anything you want, and is the whole reason for creating a custom
  57. // UIActivity
  58.  
  59. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=yourappid"]];
  60. [self activityDidFinish:YES];
  61. }
  62.  
  63. @end
  64.  
  65. #import "ActivityViewCustomActivity.h"
  66.  
  67. NSString *textItem = @"Check out the yourAppNameHere app: itunes http link to your app here";
  68. UIImage *imageToShare = [UIImage imageNamed:@"anyImage.png"];
  69.  
  70. NSArray *items = [NSArray arrayWithObjects:textItem,imageToShare,nil];
  71.  
  72. ActivityViewCustomActivity *ca = [[ActivityViewCustomActivity alloc]init];
  73.  
  74. UIActivityViewController *activityVC =
  75. [[UIActivityViewController alloc] initWithActivityItems:items
  76. applicationActivities:[NSArray arrayWithObject:ca]];
  77.  
  78. activityVC.excludedActivityTypes = @[UIActivityTypePostToWeibo, UIActivityTypeAssignToContact, UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeSaveToCameraRoll];
  79.  
  80. activityVC.completionHandler = ^(NSString *activityType, BOOL completed)
  81. {
  82. NSLog(@" activityType: %@", activityType);
  83. NSLog(@" completed: %i", completed);
  84. };
  85.  
  86. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  87. {
  88. self.popoverController = [[UIPopoverController alloc] initWithContentViewController:activityVC];
  89.  
  90. CGRect rect = [[UIScreen mainScreen] bounds];
  91.  
  92. [self.popoverController
  93. presentPopoverFromRect:rect inView:self.view
  94. permittedArrowDirections:0
  95. animated:YES];
  96. }
  97. else
  98. {
  99. [self presentViewController:activityVC animated:YES completion:nil];
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement