Created
July 1, 2014 07:03
-
-
Save kublaios/226dbea44105dd9b1c60 to your computer and use it in GitHub Desktop.
Sample iOS Game Sharing High Score With UIActivityViewController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)share:(NSNotification *)notification { | |
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, 0); | |
[self.view drawViewHierarchyInRect:self.view.bounds afterScreenUpdates:YES]; | |
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
// high score stuff | |
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"score"]) { | |
if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"score"] respondsToSelector:@selector(intValue)]) { | |
int highScore = [[[NSUserDefaults standardUserDefaults] objectForKey:@"score"] intValue]; | |
NSString *shareText = [NSString stringWithFormat:@"My Score is %i", highScore]; | |
NSArray *activityProviders = @[shareText, image]; | |
UIActivityViewController *activityViewController = | |
[[UIActivityViewController alloc] initWithActivityItems:activityProviders applicationActivities:nil]; | |
// tell the activity view controller which activities should NOT appear | |
activityViewController.excludedActivityTypes = @[UIActivityTypeAddToReadingList,UIActivityTypePostToTencentWeibo, UIActivityTypeAirDrop,UIActivityTypePrint, UIActivityTypeAssignToContact]; | |
// display the options for sharing | |
activityViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical; | |
[self presentViewController:activityViewController animated:YES completion:nil]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment