Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24345] iOS: Today Extensions cannot access App Group UserDefaults or DirectoryForSuite

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionInvalid
Resolution Date2017-01-26T22:59:03.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsiOS
Labelsn/a
ReporterLawrence Wilson
AssigneeChris Barber
Created2017-01-25T14:08:38.000+0000
Updated2017-03-24T17:44:09.000+0000

Description

On trying to implement a Today Extension and share data, i have set up an App Group and tried using Ti.App.iOS.UserDefaults, Ti.Filesystem.directoryForSuite & Ti.Wormhole all of which failed. I setup an empty XCode project called Amy Today with a Today Extension target called Amy Reminders. Having changed the target capabilities for the App Group accordingly, a Amy Today.entitlements file was created. I included the extensions using the following in the TiApp.xml:
<extensions>
    <extension projectPath="extensions/Amy Today/Amy Today.xcodeproj">
        <target name="Amy Reminders">
            <provisioning-profiles>
                <device/>
                <dist-appstore/>
                <dist-adhoc/>
            </provisioning-profiles>
        </target>
    </extension>
</extensions>
I ran the project and tested and discovered the data was being written to the appropriate App Group folder/plist correctly from the app but could not be read by the Today Extension. On further investigation I realised that a new Amy Reminders.entitlements file was being created in a new folder within the build folder and this was being included in the built project not the actual entitlements file (see attached picture - red was the one included in the project, green is the one that should have been included.) I delved into the 6.0.1.GA/iphone/cli/commands/_build.js file and discovered on line 3434 the variable entFile contained Amy Reminders/Amy Reminders.entitlement which meant the following lines that join entFile with targetName was creating this new file. This new file did not contain the key com.apple.security.application-groups which meant the Today Extension did not have the appropriate security entitlements to read the shared data. I removed the targetName from the path.join as follows:
extBuildSettings.CODE_SIGN_ENTITLEMENTS = '"' + path.join(ext.relPath, entFile) + '"';
targetInfo.entitlementsFile = path.join(this.buildDir, ext.relPath, entFile);
and the Today Extension had the correct entitlements and could read the shared data. I'm not sure if the above fix is correct as I have not tested it with Watch Extensions. Hope the above helps in the investigation on fixing this problem.

Attachments

FileDateSize
Amy entitlements.png2017-01-25T14:00:04.000+0000147370

Comments

  1. Chris Barber 2017-01-26

    Titanium supports defining App Groups in the tiapp.xml. You set them by adding them to the <ios> section of the tiapp.xml like the following.
       <ios>
           <capabilities>
               <app-groups>
                   <group>group.com.appc.foo</group>
                   <group>group.com.appc.bar</group>
               </app-groups>
           </capabilities>
       </ios>
       
    These groups are baked into the Entitlements.plist files. It's worth noting that App Groups are the only capability that is currently supported.
  2. Lawrence Wilson 2017-01-26

    So that can be used instead of creating an Entitlements.plist file in the project? Might be an idea to update the documentation then as its not stated - http://docs.appcelerator.com/platform/latest/#!/guide/tiapp.xml_and_timodule.xml_Reference Would these entitlements be included in Today Extension projects?
  3. Chris Barber 2017-01-26

    [~lawrence.wilson@abannan.com] Correct, you don't need to muck with Entitlements.plist files, at least for app groups. Yes, the docs should be updated to include the <capabilities> section. Honestly, I thought it was. I'm not familiar with "today extensions", so I'm going to guess sure.
  4. Chris Barber 2017-01-26

    I created TIDOC-2732 to document the use of the <capabilities> section in the tiapp.xml. As for this ticket, I'm going to resolve this ticket as invalid. If the <capabilities> doesn't solve the problem, then reopen this ticket with some details and I'd be happy to investigate.
  5. Lee Morris 2017-03-24

    Closing ticket as invalid with reference to the above comments.

JSON Source