-1

I would like to use one file in my iOS app & it's iMessage extension how is it possible ? With app group/shared container. Please someone write few lines. In my app I saved datas to one file and I want to load that in my iMessage extension.

let url = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
  url.appendingPathComponent(PersistanceFileName)

I used this code for my iOS app but I know the iMessage extension can't open it. So what is the solution ?

Mayur Prajapati
  • 5,454
  • 7
  • 41
  • 70
Blantrek
  • 1
  • 4

1 Answers1

0

First make sure that you’ve added your app group identifier to your app target and your iMessage extension target. You can add the app group identifier by going to the Capabilities tab under each target and scrolling down to the App Group section. Once you’ve added your app group identifier to both targets you can get the app group’s container url using the code below:

let url = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.com.myApp.appGroupIdentifier")
Jake
  • 13,097
  • 9
  • 44
  • 73
  • Now I see the file in extension, but it says: couldn’t be opened because you don’t have permission to view it. I use this code to save data: data = try PropertyListSerialization.data(fromPropertyList: propData, format: PropertyListSerialization.PropertyListFormat.binary, options: 0) try data.write(to: url) – Blantrek Feb 02 '18 at 10:20
  • I’ve updated the answer - make sure you’ve added the app group identifier to your app’s target and your iMessage target. – Jake Feb 02 '18 at 12:38