私も同じ問題を抱えていました。プロパティのUIPasteboardクラスリファレンスドキュメントによるとchangeCount
(強調は私のものです):
ペーストボードの内容が変更されるたびに (具体的には、ペーストボード項目が追加、変更、または削除されると)、UIPasteboard はこのプロパティの値を増やします。変更カウントをインクリメントした後、UIPasteboard は UIPasteboardChangedNotification (追加と変更の場合) および UIPasteboardRemovedNotification (削除の場合) という名前の通知を投稿します。...アプリケーションが再アクティブ化され、別のアプリケーションがペーストボードの内容を変更した場合にも、このクラスは変更カウントを更新します。ユーザーがデバイスを再起動すると、変更カウントはゼロにリセットされます。
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]];
}
}