Created
June 25, 2014 08:29
-
-
Save akisute/9c5a4b35bc70a37312a9 to your computer and use it in GitHub Desktop.
Use UIPasteboard to pass around data between the main app and app extensions
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
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
{ | |
// Create a pasteboard, and pass some data to it | |
// the created pasteboard can be specified as persistent as well | |
UIPasteboard *pasteboard = [UIPasteboard pasteboardWithName:@"Widget" create:YES]; | |
pasteboard.persistent = YES; | |
pasteboard.string = @"やっほー!"; | |
return YES; | |
} |
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)viewWillAppear:(BOOL)animated | |
{ | |
[super viewWillAppear:animated]; | |
// Get some data from the created pasteboard | |
UIPasteboard *pasteboard = [UIPasteboard pasteboardWithName:@"Widget" create:NO]; | |
if (pasteboard) { | |
self.titleLabel.text = pasteboard.string; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment