Heim > Fragen und Antworten > Hauptteil
这是在一个类中存储数据
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
首先你需要好好理解UIPasteboard的使用。这点可以学习这篇文章
使用剪贴板UIPasteboard
利用UIPasteboard保存data型数据时,设置pasteboardType为“public.data”,这个字符串是苹果提供的UTI,关于UTI,你可以参考一下我的文章
详解苹果提供的UTI