-
I recently upgraded my ParseSwift pod from 1.11.0 to 5.4.1 since a few users were having some issues with connecting to back4app but after upgrading and making code changes to make the app asynchronous it will not longer initialize. Below is my AppDelegate, I noticed that it will completely skip going into the "initParse" method, even if I move "try await ParseSwiftOG.initialize(applicationId: PARSE_APP_ID, clientKey: PARSE_CLIENT_KEY, serverURL: PARSE_SERVER)" into the "didFinishLaunchingWithOptions" block it will still skip it thus causing the configuration error (picture below). Any ideas how to fix this?
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Version 1.11.0 to 5.4.1 is a huge jump, you will want to make sure your keychain updates properly through that type of update. In addition, you should try your code out on a fresh install. You can look at one of my sample apps that initializes in app delegate: https://github.com/netreconlab/CareKitSample-ParseCareKit/blob/2bfee215aa080f0b1e35705fb6af7ff5e885f27a/OCKSample/Extensions/AppDelegate%2BUIApplicationDelegate.swift#L14-L21 Which is calling: https://github.com/netreconlab/ParseCareKit/blob/b30900b4664a7ae356a2f95b90c155b77c624d0d/Sources/ParseCareKit/PCKUtility.swift#L48-L94 All of the Playgrounds have been updated to the latest version of ParseSwift, so you should check there to see how to properly use: https://github.com/netreconlab/Parse-Swift/tree/main/ParseSwift.playground/Pages You are probably seeing a skip because you are unnecessarily wrapping tasks inside other tasks. Try the updated code: import ParseSwiftOG
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
private let analyticsService = AnalyticsService.shared
private let appOpenedRepository = AppOpenedRepository.shared
private let userNotificationCenter = UNUserNotificationCenter.current()
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
Task {
do {
try await initParse()
} catch {
print(“Parse not initialized: \(error)”
}
}
userNotificationCenter.requestAuthorization(options: [.alert, .sound, .badge, .carPlay]) {
granted, error in
guard granted else { return }
self.getNotificationSettings()
}
return true
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Task {
await createInstallationOnParse(deviceTokenData: deviceToken)
}
}
func applicationWillResignActive(_ application: UIApplication) {
appOpenedRepository.setLastOpenedDate()
}
func applicationWillTerminate(_ application: UIApplication) {
FilterTableViewDataSource().clearFilter()
}
}
private extension AppDelegate {
func initParse() async throws {
try await ParseSwiftOG.initialize(applicationId: PARSE_APP_ID, clientKey: PARSE_CLIENT_KEY, serverURL: PARSE_SERVER)
}
func createInstallationOnParse(deviceTokenData: Data) async {
guard var installation = try? await Installation.current() else {
return
}
installation.setDeviceToken(deviceTokenData)
do {
let updated = try await installation.save ()
print(“Saved installation: \(updated)”)
} catch {
print(“Didn’t save installation: \(error)”)
}
}
func getNotificationSettings() {
userNotificationCenter.getNotificationSettings { settings in
guard settings.authorizationStatus == .authorized else { return }
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
}
}
} |
Beta Was this translation helpful? Give feedback.
-
My apologies I thought the configuration error was because it wasn't initializing but after looking around I saw one of my query methods wasn't properly async and after fixing it, it will call the "initParse" method and I can now connect to the database. I ended up adding the deletingKeychainIfNeeded to my initialize as suggested. This is my AppDelegate for anyone else doing the jump from a previous version:
|
Beta Was this translation helpful? Give feedback.
Version 1.11.0 to 5.4.1 is a huge jump, you will want to make sure your keychain updates properly through that type of update. In addition, you should try your code out on a fresh install.
You can look at one of my sample apps that initializes in app delegate: https://github.com/netreconlab/CareKitSample-ParseCareKit/blob/2bfee215aa080f0b1e35705fb6af7ff5e885f27a/OCKSample/Extensions/AppDelegate%2BUIApplicationDelegate.swift#L14-L21
Which is calling: https://github.com/netreconlab/ParseCareKit/blob/b30900b4664a7ae356a2f95b90c155b77c624d0d/Sources/ParseCareKit/PCKUtility.swift#L48-L94
All of the Playgrounds have been updated to the latest version of ParseSwift, so you should check there to …