I want to integrate share extension into my iPhone app. App contain sqlite database which contains some of the phone book contacts. I added share extension into app and extension is also visible into share activity view controller. But the problem is that I can't access main app sqlite database. When I log the database path in extension it show different path than main application sqlite database path. So please help me about how to access main application database to fetch data from sqlite so I can show them into share extension custom view controller and also want to insert new data into database.
Add "App Groups" in Capabilities for data transfer in Main app to Extension
To share the NSUserDefaults data:
[NSUserDefaults standardUserDefaults] Replace with [[NSUserDefaults alloc] initWithSuiteName:@"group.com.XXX.XXX"];
if you copied sqlite file in document directory. So, change Document Directory path from
try! FileManager.default.url(for:.documentDirectory, in:.userDomainMask,appropriateFor: nil, create:false).appendingPathComponent(fileName)
to
let fileManager = FileManager.default
let directory = fileManager.containerURL(forSecurityApplicationGroupIdentifier: "group.com.xxx.xxx")
return directory!.appendingPathComponent(fileName).path
Target Members(both main project and
Extension) for required classestarget 'Main_App' do # Comment the next line if you're not using Swift and don't want to use dynamic frameworks use_frameworks! target 'Main_App_extension' do use_frameworks! inherit! :search_paths pod 'FMDB’ pod 'Kingfisher' end end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With