App Group Identifiers for sharing data with an extension

1,709 views
Skip to first unread message

Sam Bauch

unread,
Dec 8, 2014, 6:25:15 PM12/8/14
to rubym...@googlegroups.com
I'm trying to create a today extension that accesses core data.

According to SO answers / blogs [here, here, and here] and some vague apple docs, in order to access a shared db from an extension you first need to create an App Group and assign the extension and main app to the group. You would then create the db in the app group container so that is accessible by the main app as well as the extension.

I went ahead and created a group on the developer portal and named it "group.com.mycompanyname.myappname"

I added the following line to my Rakefile(s) for the app and extension:

  app.entitlements['com.apple.security.application-groups'] = ['group.com.mycompanyname.myappname']


But when I try to call 

    directory = NSFileManager.defaultManager.containerURLForSecurityApplicationGroupIdentifier('group.com.mycompanyname.myappname')


it returns nil rather than an NSURL.

So I'm at a bit of a loss. It's one of those things that's sort of at the nexus of RM being a second class citizen and Apple being pretty obtuse wrt to Identifiers/Profiles/Certificates (and the 'magic' that xcode handles when you do this stuff there), but I have to imagine it's possible.

Any ideas? Has anyone had success with this?


Hwee-Boon Yar

unread,
Dec 9, 2014, 12:24:49 AM12/9/14
to rubym...@googlegroups.com
What you added to your Rakefile and your code is correct, but you also need to add the app group to your app ID within the developer portal, and regenerate the provisioning profiles.

Hwee-Boon

Sam Bauch

unread,
Dec 9, 2014, 11:08:19 AM12/9/14
to rubym...@googlegroups.com
Hmm I did go through and do that but still getting nil for that directory.

I even went and did a new Group ID and new app ID and downloaded and made the changes in code & Rakefile.

One thing that is unclear to me is whether the extension rakefile and main app rakefile should have the same app ID & provisioning profile?

Colin T.A. Gray

unread,
Dec 9, 2014, 11:09:57 AM12/9/14
to rubym...@googlegroups.com
I asked Mark Villacampa about this (he's done a lot with extensions) and he had this to say:

---
Tricky... the person seems to be doing it right. This might be a simulator vs device issue, or a you-have-to-reset-the-sim issue.


There seems to be quite some people with the same symptoms:
---

:-/  Not a ton of new info, but I thought I'd pass it along.

Colin T.A. Gray
Community Manager
HipByte

Sign up for RubyMotion training! http://training.rubymotion.com



--
You received this message because you are subscribed to the Google Groups "RubyMotion - Ruby for iOS, OS X, and Android" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubymotion+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubymotion/41dad3fb-78a1-4a4d-b4a8-4f17355a2db4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sam Bauch

unread,
Dec 9, 2014, 11:33:09 AM12/9/14
to rubym...@googlegroups.com
Yeah I noticed there are a good number of others having trouble here. 

Would love to test on device but I'm getting bit by this bug right now.

Tried resetting simulator, rake clean, as well as adding the entitlements from this stack question but still no luck.

Hwee-Boon Yar

unread,
Dec 9, 2014, 11:35:09 AM12/9/14
to rubym...@googlegroups.com
For your question:

The main app and extensions need to use different identifiers, with different provisioning profiles

Hwee-Boon

Sam Bauch

unread,
Dec 9, 2014, 12:21:44 PM12/9/14
to rubym...@googlegroups.com
OK, here's an interesting bit.

I jumped over to xcode and created a test app with an extension and NSLogged the file path for an app group container. Looks like this:
'file:///Users/Sam/Library/Developer/CoreSimulator/Devices/D1AB5A1F-52D8-4E0C-AF06-849F078FF9C5/data/Containers/Shared/AppGroup/945549BA-690A-455E-96F0-B68CAF7FF837/'

Then I am able to read and write to this dir by hardcoding it, even if I leave out the entitlements to the app group

directory = NSURL.fileURLWithPath('file:///Users/Sam/Library/Developer/CoreSimulator/Devices/D1AB5A1F-52D8-4E0C-AF06-849F078FF9C5/data/Containers/Shared/AppGroup/945549BA-690A-455E-96F0-B68CAF7FF837/')

dataBaseURL
= directory.URLByAppendingPathComponent("Events.sqlite")


But I still get nil from 
NSFileManager.defaultManager.containerURLForSecurityApplicationGroupIdentifier(appGroupId)

So at least I can move on and work on other parts of my app, but does this look to any of you to be a bug on the Apple side? That I can write to an app group container without the entitlement?

Colin T.A. Gray

unread,
Dec 9, 2014, 12:26:48 PM12/9/14
to rubym...@googlegroups.com
Having just reverted from 10.10.2 to 10.10.1 due to awful flickering and Safari just failing left and right, and all my keyboards on iOS crashing, I am blaming *everything* these days on "it's a bug on apple's side."  :-|


Colin T.A. Gray
Community Manager
HipByte

Sign up for RubyMotion training! http://training.rubymotion.com



Hwee-Boon Yar

unread,
Dec 9, 2014, 12:32:04 PM12/9/14
to rubym...@googlegroups.com
Sam, I'm SO sorry!

I just remember that I have the exact same issue when running in the simulator. I ended up doing an if-else and hardcoded a path for simulator testing. It works fine on the devices though. I filed a couple of extension-related issues for RubyMotion and I forgot to file this particular one..

Hwee-Boon

Sam Bauch

unread,
Dec 9, 2014, 1:01:57 PM12/9/14
to rubym...@googlegroups.com
cool, no worries.

I will bracket the issue and report back once I'm able to deploy to device.

Thanks all!!

Sam Bauch

unread,
Dec 17, 2014, 10:20:00 AM12/17/14
to rubym...@googlegroups.com
Just to report back - now that I'm deployed to a device the code from the initial post does indeed work. Frustrating that it doesn't work on the simulator, but that looks to be an Apple bug. Thanks all!

Dave Shapiro

unread,
Dec 25, 2014, 5:45:56 PM12/25/14
to rubym...@googlegroups.com
Is it safe to say that trying to use,

NSUserDefaults.alloc.initWithSuiteName("group.com.example.app") #different group name obviously

wont work in the simulator for the above reason?

Sam Bauch

unread,
Jan 2, 2015, 12:40:50 PM1/2/15
to rubym...@googlegroups.com
I found that I was able to use that from a main app to store and retrieve in the simulator, but that the extension couldn't read from or store to it. YMMV!

--
You received this message because you are subscribed to a topic in the Google Groups "RubyMotion - Ruby for iOS, OS X, and Android" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubymotion/qDsNSf8NtXM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rubymotion+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubymotion/791348ce-9e10-47dd-8236-ce6b1ec1b1c0%40googlegroups.com.

Dave Shapiro

unread,
Jan 28, 2015, 7:40:11 PM1/28/15
to rubym...@googlegroups.com
I used the Extensionandframework sample app and still wasnt able to get the data retrieval to work on the device using this method:

NSUserDefaults.alloc.initWithSuiteName("group.com.example.app")
Message has been deleted

Doug

unread,
Jan 31, 2015, 6:08:01 PM1/31/15
to rubym...@googlegroups.com
I’m getting the same issue with NSUserDefaults.alloc.initWithSuiteName… Is there an official word on this?

Colin T.A. Gray

unread,
Feb 2, 2015, 12:03:41 PM2/2/15
to rubym...@googlegroups.com
Hey guys!  I'm going to try to look into this soon, and work with Mark Villacampa on a more in-depth sample app (and blog post!  I'll be writing blogs for rubymotion.com soon, so if you have topic requests send them my way - privately, preferred: co...@hipbyte.com)


Colin T.A. Gray
Community Manager
HipByte



On Jan 31, 2015, at 4:08 PM, Doug <doug....@gmail.com> wrote:

I’m getting the same issue with NSUserDefaults.alloc.initWithSuiteName… Is there an official word on this?

--
You received this message because you are subscribed to the Google Groups "RubyMotion - Ruby for iOS, OS X, and Android" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubymotion+...@googlegroups.com.

Dave Shapiro

unread,
Feb 2, 2015, 1:21:08 PM2/2/15
to rubym...@googlegroups.com
I eventually got it to work on the device. It just doesn't work in the Simulator.

You do need entitlements, and app certs for each extension, they don't inherit from the container (which makes sense).

Doug

unread,
Feb 10, 2015, 11:54:44 AM2/10/15
to rubym...@googlegroups.com
If it’s of any use for your sample app Colin, I’m currently using a tweaked version of CDQ (pull request opened), that works with an App Container: https://github.com/digitalfx/cdq

It’s as simple as copying the xcdatamodel to each target and adding the following to the cdq.yml file for each target:
name: App Name
app_group_id: group.com.company.AppName

And as a workaround for the simulator, the following hard codes a path:
app_group_container_uuid:  697E2EAA-A35A-4BFA-939B-B1CF6C84C5D2

(ignoring all the provisioning/code-signing stuff).

Sam Bauch

unread,
Apr 2, 2015, 11:45:52 AM4/2/15
to rubym...@googlegroups.com
Any progress on that post Colin (or anyone else that's had success with extensions)?

This time around I'm looking at photo editing extensions and can't seem to get it to show up as an option. No error, nothing, just doesn't show up.

I'm assuming it has to do with provisioning profile type stuff. I could really use a guide wrt identifiers, profiles, etc, or maybe stick some useful comments in the template's Rakefile?

Colin T.A. Gray

unread,
Apr 2, 2015, 11:55:27 AM4/2/15
to rubym...@googlegroups.com
Unfortunately I've had very little time to work on this.  I'll update the new community forum if I make headway! :-(
Reply all
Reply to author
Forward
0 new messages