mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-11 20:00:30 +01:00
App crash on receiving notification using datastack #433
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @imrobbyrc on GitHub (Jul 2, 2024).
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,
OnBoardingViewControlleris 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
@JohnEstropia commented on GitHub (Jul 2, 2024):
Can you show how your

DataStackis being initialized fromUserViewModel.init()?It's showing up in your stack trace:
@imrobbyrc commented on GitHub (Jul 2, 2024):
here's my UserVIewModel.init()
@imrobbyrc commented on GitHub (Jul 2, 2024):
i got 3 variant of that crash

here's crashlytics trace
crashlytics.zip
@JohnEstropia commented on GitHub (Jul 3, 2024):
The problem is this line:

Since your
DataStackis initialized asynchronously,publishList()is trying to start a fetch before youraddStorage()'s completion is called. I would recommend that you defer initializing any publishers on theDataStackbeforeaddStoragehas completed. That said, I wouldn't recommend converting it to a synchronous version (addStorageAndWait()) either, as eventually you will have to handle migrations and convert them back to asynchronous again.@imrobbyrc commented on GitHub (Jul 3, 2024):
hmm i think i already handle it in
OnboardingViewController.@JohnEstropia commented on GitHub (Jul 3, 2024):
I'm not sure when that
OnboardingViewControllercode is getting called, but your crash is fromHomeViewController→UserViewModelinitialization. Try putting breakpoints and check whether thepublishListcalls are called ahead of youraddStoragecompletion. Note that if you have an Storyboard set as an "Initial View Controller", that View Controller is likely to get initialized even beforeapplicationDidFinishLaunching@imrobbyrc commented on GitHub (Jul 3, 2024):
try to breakpoint in
publishListwith print in appdelete and scene delete, it called after my print statement. do you have idea how i can handleaddStorage? i useOnboardingViewControllerto handleaddStorage@imrobbyrc commented on GitHub (Jul 4, 2024):
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
(lldb) po dataStack.txt
@JohnEstropia commented on GitHub (Jul 4, 2024):
It's empty because
addStorage()is not complete yet.Add a breakpoint on the

onComplete()line here:Anything that accesses
dataStack.*methods before thatonComplete()runs is your culprit.@imrobbyrc commented on GitHub (Jul 4, 2024):
thanks for reply @JohnEstropia, but i use
DispatchGroup()to handle the flowonComplete()metho should calldispatchGroup.leave()and will notifydispatchGroup, right?@imrobbyrc commented on GitHub (Jul 4, 2024):
i got this error on corestore callback @JohnEstropia

@JohnEstropia commented on GitHub (Jul 5, 2024):
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:
addStorage()method'sonComplete()callbackHomeViewController.promotionPublisherletstored property (I'm assumingOmni.dataStackis the same as the globalvar dataStackdeclared inDataStack.swift)UserViewModel.init(), specificallylet userPublisherandlet cartPublisherdataStackthat happens right after launch@JohnEstropia commented on GitHub (Jul 5, 2024):
Sorry, scratch that. I just noticed your error in the last screenshot is in the
completionclosure itself. The error code259implies the file already exists. Do you know where/when this file is being created?@imrobbyrc commented on GitHub (Jul 5, 2024):
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
@JohnEstropia commented on GitHub (Jul 5, 2024):
I see. CoreStore doesn't set any
NSFileProtectionKeyorNSPersistentStoreFileProtectionKeyexplicitly, so the default will beNSFileProtectionCompleteUntilFirstUserAuthentication. Does the same issue happen if the notifications arrive in the lockscreen AFTER the first device passcode entry?@imrobbyrc commented on GitHub (Jul 5, 2024):
yes, as long as the device is locked it will be fail to initiate datastack
@imrobbyrc commented on GitHub (Jul 5, 2024):
how i can set data

NSPersistentStoreFileProtectionKeyandNSFileProtectionKey? i see in source code it only let variable@JohnEstropia commented on GitHub (Jul 5, 2024):
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
@imrobbyrc commented on GitHub (Jul 5, 2024):
yes i need it sooner as my crashlytics going down 😅 thankyou for your help @JohnEstropia
@JohnEstropia commented on GitHub (Jul 5, 2024):
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
@imrobbyrc commented on GitHub (Jul 5, 2024):
i think i will wait for SDK. thanks @JohnEstropia
@imrobbyrc commented on GitHub (Jul 9, 2024):
hi sorry, any update on this bro @JohnEstropia ?
@JohnEstropia commented on GitHub (Jul 17, 2024):
@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.)