2011-12-06 21 views
7

我覺得這是比我多的應用程序的SDK缺陷,但最近我一直在試圖使用UIPasteboard從我的應用程序複製字符串,它工作正常,以粘貼的地方,當我在應用程序內。的iOS - UIPasteboard沒有工作以外的應用程序

當我通過按home鍵或類似的東西跳轉到另一個應用程序,我根本就沒有複製粘貼內容的選項。

UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; 
[pasteboard setString: @"blah" ]; 
NSLog(@"%@", pasteboard.string); 

這將打印「嗒嗒」在這種情況下,每當我快速觸摸一個文本框,它會顯示粘貼選項。但是,如果我去Safari瀏覽器,Notes或郵件它並沒有顯示我的選擇。

而且,如果我從郵件複製的東西,去我的應用程序,我將不會看到藏漢粘貼選項...

+0

我有這個問題跟iOS模擬器也是如此,我認爲它只是模擬器。 –

+0

嗯,我一直在測試設備上,它不工作... –

回答

2

我有類似的問題。這可能與某些第三方圖書館有些衝突。我發現當我刪除Flurry Analytics時,一切都很好。我猜這個lib在「EnterBackground」事件上做了些什麼。

你可以嘗試「清理」你的應用程序。刪除AppDelgate的enterbackground委託的函數調用。

我的意思是你的代碼或第三方代碼,過程中可能會做某事「DidEnterBackground」,大規模你的剪貼板。儘量不要在這個任何代碼:

  • (無效)applicationDidEnterBackground:(UIApplication的*)應用程序{}

也可以嘗試刪除這就需要你在調用第三方代碼: - (BOOL)應用程序:(UIApplication *)應用程序didFinishLaunchingWithOptions:(NSDictionary *)launchOptions -

+1

你能更具體?我不明白你的關於「清理」 –

1

我能夠通過返回到Flurry 2.8.4來恢復粘貼板功能。 Flurry 3.0.2和3.0.3以某種方式禁用複製/粘貼支持與記事本等外部應用程序。

1

似乎亂舞通過釋放3.0.4

太糟糕了,解決了這個問題,我的用戶投訴淹沒了我的郵箱......

4

要執行的應用程序之間的持久紙板必須使用

UIPasteboard *pasteboard = [UIPasteboard pasteboardWithName:pasteboardIdentifier create:YES]; 
[pasteboard setPersistent:YES]; 
[pasteboard setString:string]; 
1

//保存文本

UIPasteboard* board = [UIPasteboard 
pasteboardWithName:@"com.company.wtv" create:YES]; 
board.persistent=YES; [board setValue:@"123456ccc" 
forPasteboardType:@"com.company.wtv.sharedValue"]; 

// Retrive text 

    UIPasteboard* board = [UIPasteboard pasteboardWithName:@"com.company.wtv" create:YES]; 
    board.persistent=YES; 
    NSData* result=nil; 
    NSString*resultStr=nil; 
    result =[board valueForPasteboardType:@"com.company.wtv.sharedValue"]; 
    resultStr=[[NSString alloc] initWithData:result encoding:NSUTF8StringEncoding];// I got resultStr containing 
123456ccc 

    NSLog(@"key %@",resultStr); 
+0

你能解釋一下這是如何工作的一部分? – Will

相關問題