Share Data between Project and Share Extension
Your helper function getDataSourceArray()
tries to access UserDefaults.standard
which is not shared between your host app and the extension app. You need to use the shared container.
UserDefaults.standard
-> not shared between host and extensionUserDefaults(suiteName:)
-> shared between host and extension
Try to change your function to this:
func getDataSourceArray() - > [Wishlist] ? {
if let data = UserDefaults(suiteName: UserDefaults.Keys.groupKey).value(forKey: Keys.dataSourceKey) as ? Data {
if let dataSourceArray =
try ? PropertyListDecoder().decode(Array < Wishlist > .self, from: data) as[Wishlist] {
return dataSourceArray
}
}
return nil
}
How to share Parse login session with iOS extension?
There are two possible solutions:
A) The elegant approach
Enable local data sharing which shares persistent data between the main iOS app and its extensions.
// Enable data sharing in main app.
Parse.enableDataSharingWithApplicationGroupIdentifier("...")
// Enable data sharing in app extensions.
Parse.enableDataSharingWithApplicationGroupIdentifier("...", containingApplicaiton: "...")
Local data sharing in Parse SDKs allows you do share persistent local
data between your main application and extensions that it contains,
including Keyboard, Share/Today/Photo/Action extensions and Document
Providers.
As described in the docs.
B) The manual approach
After login in the app, store the Parse session token PFUser.current().sessionToken
in an ecrypted, shared data container.
The extension can then access the session token and continue the session with PFUser.become(sessionToken:)
.
Related Topics
Tweening/Interpolating Between Two Cgpaths/Uibeziers
Uitableviewcell with Autolayout Left Margin Different on iPhone and iPad
Auto Layout in Uicollectionviewcell Not Working
Secure Keys in iOS App Scenario, Is It Safe
iOS 10 Error [Access] <Private> When Using Uiimagepickercontroller
How to Differentiate Between Iphone4 and iPhone 3
Sharing Data Between an iOS 8 Share Extension and Main App
Does Dispatch_Async(Dispatch_Get_Main_Queue(), ^{...}); Wait Until Done
How to Change Inactive Icon/Text Color on Tab Bar
How to Fix the Xcrun Unable to Find Simctl Error
Restoring Animation Where It Left Off When App Resumes from Background
How to Hide a Navigation Bar from First Viewcontroller in Swift