parse-community / Parse-SDK-iOS-OSX

The Apple SDK for Parse Platform (iOS, macOS, watchOS, tvOS)
https://parseplatform.org
Other
2.81k stars 864 forks source link

Group Identifier and Bundle Identifier are reset after initializing Parse with a `ParseClientConfiguration` #1646

Closed benpackard closed 2 years ago

benpackard commented 2 years ago

New Issue Checklist

Issue Description

To access shared state (for example PFUser.current()) in an extension, I have enabled Keychain Sharing and App Groups capabilities as per the guide. The next step is to set those values in each target just prior to initializing Parse. For example, in my extension:

Parse.enableDataSharing(withApplicationGroupIdentifier: "group.com.company.product", containingApplication: "com.company.product")

I couldn't get this to work, so I started debugging and quickly found that after initializing Parse, the following properties were empty strings:

Parse.applicationGroupIdentifierForDataSharing()
Parse.containingApplicationBundleIdentifierForDataSharing()

When accessed from either the main app, applicationGroupIdentifierForDataSharing and containingApplicationBundleIdentifierForDataSharing are empty.

Steps to reproduce

Create an app extension and configure the project per the guide, including setting Parse.enableDataSharing(withApplicationGroupIdentifier: , containingApplication: ). Initialize Parse using initializeWithConfiguration. For example:

Parse.enableDataSharing(withApplicationGroupIdentifier: "group.com.company.product")

let config = ParseClientConfiguration { config in
    config.server = "serverURL"
    config.applicationId = "applicationID"
}
Parse.initialize(with: config)

print("applicationGroupIdentifierForDataSharing: \(Parse.applicationGroupIdentifierForDataSharing())")
print("containingApplicationBundleIdentifierForDataSharing: \(Parse.containingApplicationBundleIdentifierForDataSharing())")

Actual Outcome

Parse.applicationGroupIdentifierForDataSharing() and Parse.containingApplicationBundleIdentifierForDataSharing() are empty when logged.

Expected Outcome

Parse.applicationGroupIdentifierForDataSharing() and Parse.containingApplicationBundleIdentifierForDataSharing()should return the values set prior to Parse initialization.

Environment

Sorry, not sure what this is asking for.

Client

Server

Database

Logs

parse-github-assistant[bot] commented 2 years ago

Thanks for opening this issue!

benpackard commented 2 years ago

It seems that this only happens if Parse is initialized using initialize(with: config), which I believe is the recommended approach.

If I use Parse.setApplicationId and Parse.setServer instead, the values of the sharing properties are maintained correctly. This isn't a viable solution though, since I don't use a client key which setApplicationId requires. I also built some nice environment switching based on ParseClientConfiguration that I wouldn't like to lose.

Perhaps there is a bug in initialize(with: config) that resets the values of applicationGroupIdentifierForDataSharing and containingApplicationBundleIdentifierForDataSharing.

benpackard commented 2 years ago

Not a bug. Just a difference in how to configure the environment. The correct solution if using a ParseClientConfiguration is:

ParseClientConfiguration { config in
    config.server = self.serverURL
    config.applicationId = self.applicationID

    config.applicationGroupIdentifier = "group.com.company.product"
    config.containingApplicationBundleIdentifier = "com.company.product" // only do this one from the extension
}