2012-01-02 4 views
2

UIPasteboard에 이상한 문제가 있습니다.내 UIPasteboard 코드가 작동하지 않는 이유는 무엇입니까?

나는 사파리에서 텍스트를 복사 한 다음 내 응용 프로그램에서이 코드를 사용하여 모든 데이터가 포함되어 있는지 UIPasteboard으로 찾고 있어요 : 그것은 시뮬레이터와 함께 잘 작동하지만, 아이 패드와 함께 작동하지 않습니다

[[UIPasteboard generalPasteboard] containsPasteboardTypes:[NSArray arrayWithObject:@"public.utf8-plain-text"]] 

. 캐릭터 세트 문제로 인한 것입니까?

+0

UIPasteboardTypeListString 배열을 사용하여이 문제를 해결했습니다. [[UIPasteboard generalPasteboard] containsPasteboardTypes : UIPasteboardTypeListString]; UIPasteboard * pasteboard = [UIPasteboard generalPasteboard]; if (pasteboard.string! = nil) { [self insertText : pasteboard.string]; } –

+0

이것을 답변으로 추가 한 다음 앞으로 비틀 거린 사람들을위한 답변을 수락하십시오. –

답변

4

문자 집합으로 인해이 문제가 발생했지만 IOS 5.0 또는 모든 버전에만 해당하는지 확신 할 수 없습니다. 하지만 난

[[UIPasteboard generalPasteboard] containsPasteboardTypes:UIPasteboardTypeListString]; 
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; 
if (pasteboard.string != nil) { [self insertText:pasteboard.string]; } 

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIPasteboard_Class/Reference.html

을 UIPasteboardTypeListString, 간단한 솔루션으로 내 문제를 해결 한 나는이 대답은 사람을 도울 수 있기를 바랍니다.

1

내 경험에 따르면 iOS 5에서는 일반 텍스트가 더 이상 페이스트 보드에서 public.utf8-plain-text으로 끝나지 않고 대신 public.text으로 나타납니다. 명시 적으로 문자열을 지정하는 대신 UIPasteboardTypeListString을 사용하면 작동합니다.

그래서 지금은 페이스트 보드에 일반 텍스트를 감지하는 내 코드에 다음을 사용 :

[[UIPasteboard generalPasteboard] containsPasteboardTypes:[NSArray arrayWithObjects:@"public.utf8-plain-text", @"public.text", nil]] 

또는

[[UIPasteboard generalPasteboard] containsPasteboardTypes:UIPasteboardTypeListString] 

당신이 아이폰 OS 4에 대한 시뮬레이터에서 테스트하는 경우 그입니다. x와 iPad에는 iOS 5가 설치되어 있습니까?

관련 문제