UIPasteboard有系统级别和应用级别两种类型,所以不仅可以在应用程序内通信,还能在应用程序间通信,比如我复制一个url,然后打开safari,粘贴到地址栏去,而我们可以在应用程序间通信、共享数据。
全局使用
//系统级别
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = @"复制的内容";
内部使用--copy
//应用内单独使用时
NSString * strBuildID = [[[NSBundle mainBundle]infoDictionary]objectForKey:@"CFBundleIdentifier"];
UIPasteboard * myPasteboard = [UIPasteboard pasteboardWithName:strBuildID create:YES];
myPasteboard.string = @"复制测试数据";
内部使用--paste
NSString * strBuildID = [[[NSBundle mainBundle]infoDictionary]objectForKey:@"CFBundleIdentifier"];
UIPasteboard * myPasteboard = [UIPasteboard pasteboardWithName:strBuildID create:NO];
self.pLabel.text = myPasteboard.string;
网友评论