UIPastboard不适用于iOS 7?

我正在一个iOS应用程序中,我必须在两个应用程序之间共享一些数据,我正在使用UIPastboard和数据在7.0以下的iOS中成功共享,但不在iOS 7中工作。下面是我正在使用的代码:

//编写代码….用于应用程序“A”

 NSString * name = @"peter"; NSNumber *age = [NSNumber numberWithInteger:[@"33" integerValue]]; NSMutableDictionary * dict =[[NSMutableDictionary alloc]init]; [dict setObject:name forKey:@"name"]; [dict setObject:age forKey:@"age"]; UIPasteboard * pb = [UIPasteboard pasteboardWithName:@"mypasteboard" create:YES]; [pb setPersistent:YES]; [pb setData:[NSKeyedArchiver archivedDataWithRootObject:dict] forPasteboardType:@"mydata"]; 

//读取代码…..用于应用程序“B”

  UIPasteboard * pb=[UIPasteboard pasteboardWithName:@"mypasteboard" create:NO]; NSData * data=[[NSData alloc] init]; data=[pb valueForPasteboardType:@"mydata"]; NSDictionary * dict; if (!data) { return nil; } @try { dict = [NSKeyedUnarchiver unarchiveObjectWithData:data]; } @catch (NSException* exception) { NSLog(@"Exception: %@",exception); return nil; } if(dict) //In iOS 7 dict contains 'nil' but not in iOS 6. { NSString * name = [dict objectForKey:@"name"]; NSNumber * age = [dict objectForKey:@"age"]; message =[NSString stringWithFormat:@"name =%@,\nage=%@",name,age]; } else { message =@"No data from Pasteboard"; } UIAlertView *alertView2 = [[UIAlertView alloc] initWithTitle:@"Pasteboard Data" message:message delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:Nil, nil]; alertView2.alertViewStyle = UIAlertViewStyleDefault; [alertView2 show]; 

在iOS 7中,dict包含“nil”,但在iOS 6中包含在应用程序“A”中设置的数据。

请build议我解决这个问题。

尝试这个,

 UIPasteboard * pb = [UIPasteboard pasteboardWithName:@"mypasteboard" create:YES]; [pb setPersistent:YES]; [pb setValue:[NSKeyedArchiver archivedDataWithRootObject:dict] forPasteboardType:@"mydata"];