Sharing data between the main application and today's macOS widgets

I am trying to exchange data between my main macOS application and the extension I created.
I saw that I should use "Application Groups" and exchange data with "UserDefault (package name:" name ")"

Problem: after including application groups in the main application and adding a name, I turned on application groups for the extension, and the list is empty, I don’t see the group I just created?

Any idea?

btw: command profiles are the same for both the application and the extension. I tried to delete the temporary file, clean the project, restore Xcode and the computer.

enter image description here

EDIT 1: Application groups detected in iOS project ....
EDIT 2: I tried with Xcode 9 but with the same problem .
EDIT 3: On the Apple Certificates, Identifiers and Profiles website, you don’t have the MacOS Application Groups category, is it out of date?
EDIT 4: If I add both group group names manually, I get an error:. [Custom default values] Failed to read values ​​in CFPrefsPlistSource <0x6000000e4200> (Domain: 726328455Z.test, User: kCFPreferencesAnyUser, ByHost: Yes, Container: (null)): Using kCFPreferencesAnyUser with the container is allowed only for connecting to containers fromfref, ,

Edit 5: it looks like it works, data is successfully saved using this code

UserDefaults(suiteName: "7263xxx55Z.test")!.set(selectedRow, forKey: "selectedRow") UserDefaults(suiteName: "7263xxx55Z.test")!.synchronize() 

And fetching with this code, I got the previous error, but I just ignore it

 let selectedRow = UserDefaults(suiteName: "726xxx55Z.test")!.integer(forKey: "selectedRow") 
0
xcode swift macos-sierra today-extension
Jul 04 '17 at 21:40
source share
1 answer

Exchange between app / app extension in macOS project:

1 / In the main goal of the project, select “Features” and enable “Application Groups”.

2 / Press "+" and add a new name for the application group, it should begin with the identifier of your team (for example, 643J438K.name.app)

3 / Repeat 1 / and 2 / for the target of the extension application, be sure to add the same name

4 / To save and retrieve data, use:

 // Store data UserDefaults(suiteName: "643J438K.name.app")!.set(yourVariable, forKey: "yourKey") UserDefaults(suiteName: "643J438K.name.app")!.synchronize() // Fetch data (integer type here) UserDefaults(suiteName: "643J438K.name.app")!.integer(forKey: "yourKey") 

5 / You can check if your data is saved correctly by opening this file:

 /Users/UserName/Library/Group Containers/643J438K.name.app/Preferences/643J438K.name.app.plist 
0
Jul 05 '17 at 11:56 on
source share



All Articles