我必须将数据从一个应用程序传输到另一个应用程序。当我第一次使用粘贴板传输数据时,它的工作性能很好,但是在中,我第二次从粘贴板中获得零数据时,.This问题只发生在IOS7.1设备中,它在所有其他设备中都正常。这是件奇怪的事。
我的代码如下。
// set Data
UIPasteboard* pasteBoard = [UIPasteboard pasteboardWithName:@"TEST" create:YES];
if(item == nil)
{
NSLog(@"** Set data is nil");
}
if(pasteBoard)
{
[pasteBoard setItems:[NSArray arrayWithObject:item]];
}
// Get Data
UIPasteboard* pasteboard = [UIPasteboard pasteboardWithName:@"TEST" create:NO];
NSDictionary* migrateInfo = nil;
if(pasteboard != nil && pasteboard.items.count > 0){
migrateInfo = [pasteboard.items objectAtIndex:0];
DEV_LOG(@"** Pasteboard have data");
}当我第二次传输数据时,作为migrateInfo对象获得零值。
发布于 2014-05-29 04:30:27
在此之后,我对代码进行了两次更改。
1)在我从巴斯德那里读取数据后,删除了pasteboardData
使用removePasteboardWithName.方法可以删除粘贴板数据
UIPasteboard removePasteboardWithName:PASTE_BOARD_NAME;
2)我使用了setValue函数,而不是SetItems函数。(将对象--例如NSString、NSArray、NSDictionary、NSDate、NSNumber、UIImage或NSURL对象)放在黑板上,使用setValue:forPasteboardType: method)。
https://stackoverflow.com/questions/23260101
复制相似问题