2010-11-21 4 views
10

이 방법이 있습니까? 실행시에 UIPasteboardChangedNotification에 대한 객체를 등록하지만 배경으로 보내고 (예를 들어) Safari를 열고 일부 텍스트를 복사 할 때 내 핸들러가 호출되지 않습니다. (지금은 시뮬레이터 만 사용하고 있습니다).백그라운드에서 UIPasteboard (generalPasteboard) 알림을 수신 중입니다.

둘 다 사용했습니다 :

[[NSNotificationCenter defaultCenter] addObserver:self 
    selector:@selector(pasteboardNotificationReceived:) 
    name:UIPasteboardChangedNotification 
    object:[UIPasteboard generalPasteboard]]; 

과 :

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

을 내 핸들러를 등록 할 수 있습니다.

+0

를 해결나요? 나는 또한 이것을 성취하려고 노력하고있다. http://cl.ly/69a4 답을 찾았 으면 나와 공유해 주시겠습니까? – Frankrockz

답변

11

나는 동일한 문제가있었습니다. (강조 광산 임) changeCount 속성의 UIPasteboard Class Reference 문서에 따르면

마다이 속성의 판지 변경-특히 판지 항목을 추가, 수정 또는시 제거-UIPasteboard가 증가 값의 내용. 변경 카운트가 증가하면 UIPasteboard는 UIPasteboardChangedNotification (추가 및 수정의 경우) 및 UIPasteboardRemovedNotification (제거의 경우)이라는 알림을 게시합니다. ... 클래스는 또한 응용 프로그램이 다시 활성화되고 다른 응용 프로그램이 대지 내용을 변경하면 변경 횟수 을 업데이트합니다. 사용자가 장치를 다시 시작하면 변경 횟수가 0으로 재설정됩니다.

이 내용은 앱이 다시 활성화되면 내 애플리케이션이 UIPasteboardChangedNotification 알림을 수신한다는 의미입니다. 그러나주의 깊게 읽으면 앱이 다시 활성화 될 때 업데이트되는 것은 changeCount뿐입니다.

응용 프로그램이 배경에있는 동안 changeCount이 변경된 것을 발견하면 내 응용 프로그램 대리인의 페이스트 보드 changeCount을 추적하고 예상 알림을 게시하여 처리했습니다. 응용 프로그램 위임의 인터페이스에서

:

NSUInteger pasteboardChangeCount_; 

앱 위임의 구현

: 당신은 지금이

- (BOOL)application:(UIApplication*)application 
    didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { 
    [[NSNotificationCenter defaultCenter] 
    addObserver:self 
    selector:@selector(pasteboardChangedNotification:) 
    name:UIPasteboardChangedNotification 
    object:[UIPasteboard generalPasteboard]]; 
    [[NSNotificationCenter defaultCenter] 
    addObserver:self 
    selector:@selector(pasteboardChangedNotification:) 
    name:UIPasteboardRemovedNotification 
    object:[UIPasteboard generalPasteboard]]; 

    ... 
} 

- (void)pasteboardChangedNotification:(NSNotification*)notification { 
    pasteboardChangeCount_ = [UIPasteboard generalPasteboard].changeCount; 
} 

- (void)applicationDidBecomeActive:(UIApplication*)application { 
    if (pasteboardChangeCount_ != [UIPasteboard generalPasteboard].changeCount) { 
    [[NSNotificationCenter defaultCenter] 
    postNotificationName:UIPasteboardChangedNotification 
    object:[UIPasteboard generalPasteboard]]; 
    } 
} 
+0

하지만 제대로 작동하지 않을 때만이 솔루션이 백그라운드에서 앱을 실행하는 동안 알림을 모니터링 할 수 없습니다. –

관련 문제