iOS 6:UserInfo为粘贴板更改通知返回nil

时间:2012-12-09 16:21:00

标签: iphone objective-c ios6 nsnotificationcenter uipasteboard

以下是粘贴板更改事件的通知观察器,我需要它来处理复制的选定文本

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(receiveClipBoardNotification:)
                                             name:@"UIPasteboardChangedNotification"
                                           object:nil];

以下是选择器方法的实现 receiveClipBoardNotification:

- (void) receiveClipBoardNotification:(NSNotification *) notification {

//    NSMutableArray *typesAddedKey = [[notification userInfo] objectForKey:@"UIPasteboardChangedTypesAddedKey"];
//    pasteBoardItemType = [typesAddedKey objectAtIndex:0];        

    NSLog(@"%@", [notification userInfo]);
}

问题是 [通知userInfo] 在iOS 6上返回nil,尽管它在iOS 5上运行良好。

1 个答案:

答案 0 :(得分:0)

嗯,这适用于iOS 6

NSLog(@"%@", [[UIPasteboard generalPasteboard] string]);