Skip to content

Instantly share code, notes, and snippets.

@akisute
Created June 25, 2014 08:29
Show Gist options
  • Save akisute/9c5a4b35bc70a37312a9 to your computer and use it in GitHub Desktop.
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
- (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;
}
- (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