这是在一个类中存储数据
UIPasteboard *pasteboard4 = [UIPasteboard pasteboardWithName:@"Pasteboard4" create:YES];
NSDictionary *loginDic = [NSDictionary dictionaryWithObject:@"用户名密码登陆" forKey:@"getKSWay"];
NSData *loginDictData = [NSKeyedArchiver archivedDataWithRootObject:loginDic];
[pasteboard4 setData:loginDictData forPasteboardType:@"getKSWay"];
然后在另一个类中读取
UIPasteboard *pb = [UIPasteboard pasteboardWithName:@"Pasteboard4" create:NO];
NSDictionary *dict = [NSKeyedUnarchiver unarchiveObjectWithData:[pb dataForPasteboardType:@"getKSWay"]];
NSLog(@"登陆方式:%@",[dict objectForKey:@"getKSWay"]);
输出是null
给我你的怀抱2017-04-28 09:08:15
First of all, you need to understand the use of UIPasteboard. You can learn this from this article
Use the clipboard UIPasteboard
When using UIPasteboard to save data type data, set the pasteboardType to "public.data". This string is the UTI provided by Apple. Regarding UTI, you can refer to my article
Detailed explanation of UTI provided by Apple