objective-c - 请问UIPasteboard在一个类中存储数据后如何在另一个类中读取数据?
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-04-28 09:06:15
0
1
699

这是在一个类中存储数据
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
曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(1)
给我你的怀抱

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!