2016-10-21 33 views
0

我有兩個應用程序,都在同一個應用程序組...我只是想在他們之間共享一個字符串。應用程序數據共享不起作用

NSUserDefaults * defaultsStore = [[NSUserDefaults alloc] initWithSuiteName:@"group.my.bundle.id"]; 
[defaultsStore setObject:@"TEST" forKey:@"Testing"]; 
[defaultsStore synchronize]; 

在其他應用程序,這也是除了應用程序組我有

NSUserDefaults * defaultsStore = [[NSUserDefaults alloc] initWithSuiteName:@"group.my.bundle.id"]; 
NSString * testingString = [defaultsStore objectForKey:@"Testing"]; 

似乎沒有任何工作。我不認爲我必須制定擴展目標,因爲它們是獨立的獨立應用程序?

的defaultsStore不爲空,但該容器對象總是空..

任何幫助,將不勝感激

回答

0

您的應用程序組沒有設置正確,你arenot使用正確的組ID initWithSuiteName:

+0

它與能力部分 – renners

0

爲了使用應用組使用的應用程序之間的數據共享必須按照以下步驟做如下設置:

1.在Project Navigator中點擊*.xcodeproj文件。

  1. 在項目導航器的右側查找項目和目標。在目標下點擊你的主要目標(應該是目標下的第一件事)。 朝頂部點擊Capabilities選項卡。

  2. 在應用程序組部分中,單擊右側的開關以打開應用程序組ON

  3. 點擊+按鈕,並添加名爲group.my.bundle.id的應用組。 轉到其他應用程序中的相同位置,現在應該可以選擇此組。爲將要使用此共享數據的每個應用啓用此組。

注:請您在應用程序中之間共享數據相同。

讀ansers這裏獲得更多的幫助:Communicating and persisting data between apps with App Groups

也紅了文檔瀏覽:

https://developer.apple.com/library/content/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html#//apple_ref/doc/uid/TP40014214-CH21-SW6

+0

中顯示的組ID相同 – renners

0

您必須啓用從Targets-> Compabilities App Groupsenter image description here

Here是簡單的教程。

+0

已經完成 – renners

相關問題