-
-
Notifications
You must be signed in to change notification settings - Fork 255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
App crash on receiving notification using datastack #508
Comments
here's my UserVIewModel.init() class UserViewModel: ObservableObject {
private let userPublisher = dataStack.publishList(From<Membership>().orderBy(.ascending(\.$id)))
private let cartPublisher = Omni.dataStack.publishList(From<Omni.Cart>().orderBy(.ascending(\.$storeCode)))
@ObjectState var user: ObjectSnapshot<Membership>?
@Published var progress: Double = 0
@Published var spendingToNextTier: Double = 0
@Published var membershipStatus: MembershipStatus = .member
init() {
_user = .init(userPublisher.snapshot.first)
progress = 0
spendingToNextTier = 0
userPublisher.addObserver(self, notifyInitial: true) { [weak self] publisher in
guard let self else { return }
let snapshot: ListSnapshot<Membership> = publisher.snapshot
guard let user = snapshot.first else {
self.progress = 0
self.spendingToNextTier = 0
self.membershipStatus = .member
return
}
self._user = .init(user)
let upgradeSpending = Double(user.upgradeSpending ?? 0)
let totalSpending = Double(user.totalSpending ?? 0)
let difference = upgradeSpending - totalSpending
self.progress = upgradeSpending == 0 ? 100 : (upgradeSpending - difference) / upgradeSpending * 100
self.spendingToNextTier = difference
self.membershipStatus = MembershipStatus(rawValue: user.membershipStatus ?? 100) ?? .member
} }
deinit {
userPublisher.removeObserver(self)
}
} |
here's crashlytics trace |
Since your |
hmm i think i already handle it in let dispatchGroup = DispatchGroup()
dispatchGroup.enter()
Stamps.createDataStack {
dispatchGroup.leave()
}
dispatchGroup.enter()
Omni.createDataStack {
dispatchGroup.leave()
}
dispatchGroup.notify(queue: .main) {
guard dataStack != nil || Omni.dataStack != nil else {
print("Error: dataStack is not initialized")
return
}
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let mainTabBarController = storyboard.instantiateViewController(identifier: "MarugameTabbarViewController")
(UIApplication.shared.connectedScenes.first?.delegate as? SceneDelegate)?.changeRootViewController(mainTabBarController)
} |
I'm not sure when that |
try to breakpoint in |
hi @JohnEstropia , i got a reason why it crash, the initialize dataStack is complete but persistentStore is empty, you can see this log, do you know why it still empty? it's crash when the device in lock state |
thanks for reply @JohnEstropia, but i use let dispatchGroup = DispatchGroup()
dispatchGroup.enter()
Omni.createDataStack {
dispatchGroup.leave()
}
dispatchGroup.enter()
Stamps.createDataStack {
dispatchGroup.leave()
}
dispatchGroup.notify(queue: .main) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let mainTabBarController = storyboard.instantiateViewController(identifier: "MarugameTabbarViewController")
(UIApplication.shared.connectedScenes.first?.delegate as? SceneDelegate)?.changeRootViewController(mainTabBarController)
if Membership.isAuthenticated, !Defaults.deviceToken.isEmpty {
registerPushNotificationKey()
}
Session.setCrashlyticsData()
UIApplication.shared.registerForRemoteNotifications()
}
}
|
i got this error on corestore callback @JohnEstropia |
Sorry if I wasn't clear. The breakpoints are to find the order of events happening in your app. You'd need to compare which of the following is hit first:
|
Sorry, scratch that. I just noticed your error in the last screenshot is in the |
the file should be exists because if i open the apps normaly it will be fine, the problem is when the apps backgroundly launched by push notification in locked state |
I see. CoreStore doesn't set any |
yes, as long as the device is locked it will be fail to initiate datastack |
I'll add a way to set these flags. In the meantime, if you need it sooner you might want to fork CoreStore temporarily and add the necessary flags in the code you screenshot above |
yes i need it sooner as my crashlytics going down 😅 thankyou for your help @JohnEstropia |
Another approach would be to present a separate notification when the device has not been authenticated. If your users' data are loaded from that store, you might want to keep them encrypted for security. Regardless, I'll notify this thread after I update the SDK |
i think i will wait for SDK. thanks @JohnEstropia |
hi sorry, any update on this bro @JohnEstropia ? |
@imrobbyrc Since I cannot promise a release date on this update, please fork and implement the protection flags on your side for now. While this looks like an easy fix for some simple use cases, supporting it on the API level means CoreStore should be able to handle any failures related to access protections so I'd like to do it correctly for common use cases (ex: deeplinks from push notifications like yours, background fetches etc.) |
Crashlog: testflight_feedback.zip
the is intermittent, when the device recieved notifcation but apps is not running, it will crash. it doesnt happend when apps open or in background state.
my apps flow is,
OnBoardingViewController
is the main viewcontroller where apps open, its setup from datastack after that it'll setupTabBar like code above, here's some code for NotificationServiceExtension and other important codehope you can help me with this @JohnEstropia
notification extension
Datastack for notification extension
delegate for notification
my main datastack
datastack
Homeviewcontroller where the crash is
The text was updated successfully, but these errors were encountered: