Forum Xamarin.iOS

How can I share folders in the Resources directory between ios app and app extension?

I have a library project which contains a resources folder with subfolders. I expected this to allow the app extension and app to share the exact same files. However, when I inspect the final .ipa file, folders in the Resources directory are copied to the application root and the root folder of the .appex plugin. Is there a way to share these files and images without duplicating them?

Answers

  • AndyMartin.6838AndyMartin.6838 USMember ✭✭
    edited January 2017

    It seems like the answer is to use a framework, which has to be made with Xcode. This raises a few problems with Xamarin.

    1. Now if we want to share code between an app and app extension, we have to write it in Objective-C. Otherwise, we get duplicate instances of the same code.
    2. If we want to share image assets between an app and app extension, we have to include them in the framework. No longer do we get to use Xamarin for that.
    3. When using the same package in our app and app extension, we will always get duplicate code.

    Isn't there something Xamarin could do to help us here? I think this is a horrible downside to using Xamarin for iOS development.

  • GavinGrantGavinGrant GBUniversity ✭✭✭

    Have you looked at App Groups. Try this link
    https://developer.apple.com/library/content/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html

    It talks about sharing a single set of pre rendered assets.

    Would that be what you're trying to do

  • AndyMartin.6838AndyMartin.6838 USMember ✭✭

    @GavinGrant said:
    Have you looked at App Groups. Try this link
    https://developer.apple.com/library/content/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html

    It talks about sharing a single set of pre rendered assets.

    Would that be what you're trying to do

    I reread that part of the documentation after you mentioned it. It seems to me that you can only write to NSUserDefaults at runtime. Then there is the option for the shared container. Do you know how to write to the shared container at compile time?

  • GavinGrantGavinGrant GBUniversity ✭✭✭

    I've not done that before, but if I understand the document correctly, you don't need to share at compile time. The assets can reside in the app and the extension stares access to the assets.

  • AndyMartin.6838AndyMartin.6838 USMember ✭✭

    @GavinGrant said:
    I've not done that before, but if I understand the document correctly, you don't need to share at compile time. The assets can reside in the app and the extension stares access to the assets.

    I appreciate the response, but what I need is to know how to make them reside in the app.

Sign In or Register to comment.