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 code
hope you can help me with this @JohnEstropia
notification extension
classNotificationService:UNNotificationServiceExtension{varcontentHandler:((UNNotificationContent)->Void)?varbestAttemptContent:UNMutableNotificationContent?overridefuncdidReceive(_request:UNNotificationRequest,withContentHandlercontentHandler:@escaping(UNNotificationContent)->Void){self.contentHandler=contentHandlerbestAttemptContent=(request.content.mutableCopy()as?UNMutableNotificationContent)guardletbestAttemptContent=bestAttemptContentelse{contentHandler(request.content)return}vardata=bestAttemptContent.userInfoas![String:Any]guard(try?notificationDataStack.perform(synchronous:{transactioninletnotification=trytransaction.importUniqueObject(Into<Notification>(),source:bestAttemptContent)data["id"]=notification?.id??""bestAttemptContent.userInfo=databestAttemptContent.badge=trytransaction.fetchCount(From<Notification>(),Where<Notification>("read == %@",false))asNSNumberreturnnotification}))!=nilelse{contentHandler(bestAttemptContent)return}guardletattachment=request.attachmentelse{contentHandler(bestAttemptContent)return}bestAttemptContent.attachments=[attachment]contentHandler(bestAttemptContent)}overridefuncserviceExtensionTimeWillExpire(){// Called just before the extension will be terminated by the system.// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.ifletcontentHandler=contentHandler,letbestAttemptContent=bestAttemptContent{contentHandler(bestAttemptContent)}}}
Datastack for notification extension
//// NotificationDataStack.swift// NotificationService//// Created by Heryanto on 03/08/23.//importCoreStorepublicvarnotificationDataStack:DataStack={letdataStack=DataStack(CoreStoreSchema(modelVersion:"V1",entities:[Entity<Notification>("Notification"),],versionLock:["Notification":[0x22cf99de208e3ec2,0x7829fbcec773a143,0x2ce736cf3e20956b,0x98417222b0f0cb7f]]))letfileURL=FileManager.default.containerURL(forSecurityApplicationGroupIdentifier:"group.marugame.udon")?.appendingPathComponent("MarugamePN.sqlite")try!dataStack.addStorageAndWait(SQLiteStore(fileURL:fileURL!,localStorageOptions:.allowSynchronousLightweightMigration))returndataStack}()
delegate for notification
extensionSceneDelegate:UNUserNotificationCenterDelegate{funcuserNotificationCenter(_:UNUserNotificationCenter,willPresent_:UNNotification,withCompletionHandlercompletionHandler:@escaping(UNNotificationPresentationOptions)->Void){// Need to do this because observer doesn't notify by extension servicetry?notificationDataStack.perform(synchronous:{transactioninletnotif=try!transaction.fetchOne(From<Notification>(),OrderBy<Notification>(.descending("created")))notif?.read=false},waitForAllObservers:true)completionHandler([.banner,.sound,.badge])}
my main datastack
classOnBoardingViewController:UIViewController{overridefuncviewWillAppear(_animated:Bool){super.viewWillAppear(false)letdispatchGroup=DispatchGroup()dispatchGroup.enter()Stamps.createDataStack{dispatchGroup.leave()}dispatchGroup.enter()Omni.createDataStack{dispatchGroup.leave()}dispatchGroup.notify(queue:.main){guarddataStack!=nil||Omni.dataStack!=nilelse{print("Error: dataStack is not initialized")return}letstoryboard=UIStoryboard(name:"Main",bundle:nil)letmainTabBarController=storyboard.instantiateViewController(identifier:"MarugameTabbarViewController")(UIApplication.shared.connectedScenes.first?.delegateas?SceneDelegate)?.changeRootViewController(mainTabBarController)}}}funcsetupTabs(window:UIWindow?){guardletwindow=windowelse{return}lethomeNavigationController=HomeViewController.instantiate()lethomeNavigationController2=UINavigationController()homeNavigationController2.tabBarItem.title="Scan QR"letorderNavigationController=UINavigationController(rootViewController:MarugameHostingController(rootView:OrderIndexView(),hidesNavigationBar:false,hidesBottomBar:false,navigationTitle:"Order History"))orderNavigationController.tabBarItem=UITabBarItem(title:"Orders",image:UIImage(named:"tab-order-icon"),tag:2)letaccountNavigationController=UINavigationController(rootViewController:MarugameHostingController(rootView:AccountView(),hidesNavigationBar:false,hidesBottomBar:false,navigationTitle:"Account"))accountNavigationController.tabBarItem=UITabBarItem(title:"Account",image:UIImage(named:"tab-account-icon"),tag:3)letpromotionNavigationController=UINavigationController(rootViewController:MarugameHostingController(rootView:PromotionView(),hidesNavigationBar:false,hidesBottomBar:false,navigationTitle:"Promotion"))promotionNavigationController.tabBarItem=UITabBarItem(title:"Promos",image:UIImage(named:"tab-promotion-icon"),tag:4)letviewControllers=[homeNavigationController,promotionNavigationController,homeNavigationController2,orderNavigationController,accountNavigationController]iflettabBarController=window.rootViewControlleras?UITabBarController{tabBarController.viewControllers=viewControllerstabBarController.selectedIndex=TabBar.home.rawValue}}funcchangeRootViewController(_vc:UIViewController,animated:Bool=true){guardletwindow=windowelse{return}window.rootViewController=vcsetupTabs(window:window)// add animationUIView.transition(with:window,duration:0.5,options:[.transitionCrossDissolve],animations:nil,completion:nil)}}
datastack
//// DataStack.swift// Marugame//// Created by Robby Chandra on 21/06/23.//importFoundationimportCoreStorepublicvardataStack:DataStack!publicenumStamps{publicstaticfunccreateDataStack(onComplete:@escaping(()->Void)){dataStack=DataStack(CoreStoreSchema(modelVersion:"V1",entities:[Entity<V1.Banner>("Banner"),Entity<V1.Membership>("Membership"),Entity<V1.Reward>("Reward"),Entity<V1.RewardGroup>("RewardGroup"),Entity<V1.Voucher>("Voucher"),Entity<V1.VoucherGroup>("VoucherGroup"),Entity<V1.Popup>("Popup"),],versionLock:["Banner":[0x600e0c14f3174fb0,0x4ad7883b64d50159,0x61eb8f07e1a3ac42,0xa9a8fdb774a082ba],"Membership":[0x1dc90a60c450342a,0xb67e77733adf96a8,0x64763eba800d5273,0x94b19686bf002575],"Popup":[0x59e3bb649ca969c9,0x67753f46d0fbafc1,0x66c20abb7e408f53,0x23c14ac6aa576899],"Reward":[0x7b978dd5baf85d35,0x8ca7bdb318cb025b,0x7ec6fe07d986af88,0xbb9b39bdbc340260],"RewardGroup":[0xfcb44158673027ac,0xd0ab5bcec8ad468c,0x46bf8d5567c9cd02,0x60a9c4ed47e6327c],"Voucher":[0x19afba96c2fc110,0xc0b3d8e36fa2f16b,0xe58993540fde531e,0x902a853074dbd3ed],"VoucherGroup":[0x51f96443bfdd74b9,0x157a1554c645e71a,0x5e62338caf15efee,0xf7a691441c6e36cf]]),CoreStoreSchema(modelVersion:"V2",entities:[Entity<V2.Banner>("Banner"),Entity<V2.Membership>("Membership"),Entity<V2.Reward>("Reward"),Entity<V2.RewardGroup>("RewardGroup"),Entity<V2.Voucher>("Voucher"),Entity<V2.VoucherGroup>("VoucherGroup"),Entity<V2.Popup>("Popup"),],versionLock:["Banner":[0x600e0c14f3174fb0,0x4ad7883b64d50159,0x61eb8f07e1a3ac42,0xa9a8fdb774a082ba],"Membership":[0x63b864e8cc8a2182,0xad5f6fb0637c34b,0xb736c06b81df2a9,0x92d92d1c7086be6e],"Popup":[0x59e3bb649ca969c9,0x67753f46d0fbafc1,0x66c20abb7e408f53,0x23c14ac6aa576899],"Reward":[0x7b978dd5baf85d35,0x8ca7bdb318cb025b,0x7ec6fe07d986af88,0xbb9b39bdbc340260],"RewardGroup":[0xfcb44158673027ac,0xd0ab5bcec8ad468c,0x46bf8d5567c9cd02,0x60a9c4ed47e6327c],"Voucher":[0x19afba96c2fc110,0xc0b3d8e36fa2f16b,0xe58993540fde531e,0x902a853074dbd3ed],"VoucherGroup":[0x51f96443bfdd74b9,0x157a1554c645e71a,0x5e62338caf15efee,0xf7a691441c6e36cf]]),CoreStoreSchema(modelVersion:"V3",entities:[Entity<Banner>("Banner"),Entity<Membership>("Membership"),Entity<Reward>("Reward"),Entity<RewardGroup>("RewardGroup"),Entity<Voucher>("Voucher"),Entity<VoucherGroup>("VoucherGroup"),Entity<Popup>("Popup"),],versionLock:["Banner":[0x600e0c14f3174fb0,0x4ad7883b64d50159,0x61eb8f07e1a3ac42,0xa9a8fdb774a082ba],"Membership":[0x63b864e8cc8a2182,0xad5f6fb0637c34b,0xb736c06b81df2a9,0x92d92d1c7086be6e],"Popup":[0x59e3bb649ca969c9,0x67753f46d0fbafc1,0x66c20abb7e408f53,0x23c14ac6aa576899],"Reward":[0x7b978dd5baf85d35,0x8ca7bdb318cb025b,0x7ec6fe07d986af88,0xbb9b39bdbc340260],"RewardGroup":[0xfcb44158673027ac,0xd0ab5bcec8ad468c,0x46bf8d5567c9cd02,0x60a9c4ed47e6327c],"Voucher":[0x8a01201f48e41d4,0xf69b81f62cd316c3,0x21205dd2ef575eb9,0xde79162edd1ad468],"VoucherGroup":[0x51f96443bfdd74b9,0x157a1554c645e71a,0x5e62338caf15efee,0xf7a691441c6e36cf]]),migrationChain:["V1","V2","V3"])try?dataStack.addStorage(SQLiteStore(fileName:"Marugame.sqlite",localStorageOptions:.allowSynchronousLightweightMigration)){_inonComplete()}}}publicvarpreviewDataStack:DataStack={letdataStack=DataStack(CoreStoreSchema(modelVersion:"V2",entities:[Entity<Banner>("Banner"),Entity<Membership>("Membership"),Entity<Notification>("Notification"),Entity<Popup>("Popup"),Entity<Reward>("Reward"),Entity<RewardGroup>("RewardGroup"),Entity<Voucher>("Voucher"),Entity<VoucherGroup>("VoucherGroup"),]))try!dataStack.addStorageAndWait(InMemoryStore())returndataStack}()
Can you show how your DataStack is being initialized from UserViewModel.init()?
It's showing up in your stack trace:
@JohnEstropia commented on GitHub (Jul 2, 2024):
Can you show how your `DataStack` is being initialized from `UserViewModel.init()`?
It's showing up in your stack trace:
<img width="1243" alt="Screenshot 2024-07-02 at 20 08 57" src="https://github.com/JohnEstropia/CoreStore/assets/3029684/7e39a7ea-ef02-4de8-b4a0-ad61914cd3db">
Since your DataStack is initialized asynchronously, publishList() is trying to start a fetch before your addStorage()'s completion is called. I would recommend that you defer initializing any publishers on the DataStack before addStorage has 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.
@JohnEstropia commented on GitHub (Jul 3, 2024):
The problem is this line:
<img width="802" alt="Screenshot 2024-07-03 at 9 46 15" src="https://github.com/JohnEstropia/CoreStore/assets/3029684/fa726ba4-b74f-40ff-bf8b-e5940452590f">
Since your `DataStack` is initialized asynchronously, `publishList()` is trying to start a fetch before your `addStorage()`'s completion is called. I would recommend that you defer initializing any publishers on the `DataStack` before `addStorage` has 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.
Since your DataStack is initialized asynchronously, publishList() is trying to start a fetch before your addStorage()'s completion is called. I would recommend that you defer initializing any publishers on the DataStack before addStorage has 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.
hmm i think i already handle it in OnboardingViewController.
letdispatchGroup=DispatchGroup()dispatchGroup.enter()Stamps.createDataStack{dispatchGroup.leave()}dispatchGroup.enter()Omni.createDataStack{dispatchGroup.leave()}dispatchGroup.notify(queue:.main){guarddataStack!=nil||Omni.dataStack!=nilelse{print("Error: dataStack is not initialized")return}letstoryboard=UIStoryboard(name:"Main",bundle:nil)letmainTabBarController=storyboard.instantiateViewController(identifier:"MarugameTabbarViewController")(UIApplication.shared.connectedScenes.first?.delegateas?SceneDelegate)?.changeRootViewController(mainTabBarController)}
@imrobbyrc commented on GitHub (Jul 3, 2024):
> The problem is this line: <img alt="Screenshot 2024-07-03 at 9 46 15" width="802" src="https://private-user-images.githubusercontent.com/3029684/345243604-fa726ba4-b74f-40ff-bf8b-e5940452590f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk5NzI0MjQsIm5iZiI6MTcxOTk3MjEyNCwicGF0aCI6Ii8zMDI5Njg0LzM0NTI0MzYwNC1mYTcyNmJhNC1iNzRmLTQwZmYtYmY4Yi1lNTk0MDQ1MjU5MGYucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcwMyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MDNUMDIwMjA0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9Njc5ZDZmMGE0ZGJlODFjZjRkM2MxYjExN2FiZGRmYjBjM2FjY2EwNDFjMDEzOTdiNmUyYWY1YzAxZTI5OWVkMyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.TpCbP0re_VhaXY3OvCbReCK8hrHOv0V339O-yQ5TUCI">
>
> Since your `DataStack` is initialized asynchronously, `publishList()` is trying to start a fetch before your `addStorage()`'s completion is called. I would recommend that you defer initializing any publishers on the `DataStack` before `addStorage` has 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.
hmm i think i already handle it in `OnboardingViewController`.
``` swift
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 OnboardingViewController code is getting called, but your crash is from HomeViewController → UserViewModel initialization. Try putting breakpoints and check whether the publishList calls are called ahead of your addStorage completion. Note that if you have an Storyboard set as an "Initial View Controller", that View Controller is likely to get initialized even before applicationDidFinishLaunching
@JohnEstropia commented on GitHub (Jul 3, 2024):
I'm not sure when that `OnboardingViewController` code is getting called, but your crash is from `HomeViewController` → `UserViewModel` initialization. Try putting breakpoints and check whether the `publishList` calls are called ahead of your `addStorage` completion. Note that if you have an Storyboard set as an "Initial View Controller", that View Controller is likely to get initialized even before `applicationDidFinishLaunching`
I'm not sure when that OnboardingViewController code is getting called, but your crash is from HomeViewController → UserViewModel initialization. Try putting breakpoints and check whether the publishList calls are called ahead of your addStorage completion. Note that if you have an Storyboard set as an "Initial View Controller", that View Controller is likely to get initialized even before applicationDidFinishLaunching
try to breakpoint in publishList with print in appdelete and scene delete, it called after my print statement. do you have idea how i can handle addStorage ? i use OnboardingViewController to handle addStorage
@imrobbyrc commented on GitHub (Jul 3, 2024):
> I'm not sure when that `OnboardingViewController` code is getting called, but your crash is from `HomeViewController` → `UserViewModel` initialization. Try putting breakpoints and check whether the `publishList` calls are called ahead of your `addStorage` completion. Note that if you have an Storyboard set as an "Initial View Controller", that View Controller is likely to get initialized even before `applicationDidFinishLaunching`
try to breakpoint in `publishList ` with print in appdelete and scene delete, it called after my print statement. do you have idea how i can handle `addStorage` ? i use `OnboardingViewController` to handle `addStorage`
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
@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](https://github.com/user-attachments/files/16096301/lldb.po.dataStack.txt)
It's empty because addStorage() is not complete yet.
Add a breakpoint on the onComplete() line here:
Anything that accesses dataStack.* methods before that onComplete() runs is your culprit.
@JohnEstropia commented on GitHub (Jul 4, 2024):
> do you know why it still empty?
It's empty because `addStorage()` is not complete yet.
Add a breakpoint on the `onComplete()` line here:
<img width="521" alt="Screenshot 2024-07-04 at 18 35 33" src="https://github.com/JohnEstropia/CoreStore/assets/3029684/1d047591-7c1b-4dfc-b212-434cfcdec023">
Anything that accesses `dataStack.*` methods before that `onComplete()` runs is your culprit.
onComplete() metho should call dispatchGroup.leave() and will notify dispatchGroup, right?
@imrobbyrc commented on GitHub (Jul 4, 2024):
> > do you know why it still empty?
>
> It's empty because `addStorage()` is not complete yet.
>
> Add a breakpoint on the `onComplete()` line here: <img alt="Screenshot 2024-07-04 at 18 35 33" width="521" src="https://private-user-images.githubusercontent.com/3029684/345778103-1d047591-7c1b-4dfc-b212-434cfcdec023.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjAwODY3OTEsIm5iZiI6MTcyMDA4NjQ5MSwicGF0aCI6Ii8zMDI5Njg0LzM0NTc3ODEwMy0xZDA0NzU5MS03YzFiLTRkZmMtYjIxMi00MzRjZmNkZWMwMjMucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcwNCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MDRUMDk0ODExWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NjlkNTdjZTg5OTk1MzlkMjE0MDhiN2Q2MWM3OTE3NDkyOTJkNzZmMDcwNDA5YjA3NTYwNmRmNWQ5OTAyNDBkNyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.2qINmQBySJ5TQrmm3fSb07zGVU21GVXh1h5GGg9ZAns">
>
> Anything that accesses `dataStack.*` methods before that `onComplete()` runs is your culprit.
thanks for reply @JohnEstropia, but i use `DispatchGroup()` to handle the flow
``` swift
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()
}
}
```
`onComplete()` metho should call `dispatchGroup.leave()` and will notify `dispatchGroup`, right?
i got this error on corestore callback @JohnEstropia
@imrobbyrc commented on GitHub (Jul 4, 2024):
i got this error on corestore callback @JohnEstropia
<img width="1440" alt="Screenshot 2024-07-04 at 17 36 41" src="https://github.com/JohnEstropia/CoreStore/assets/25898417/7c37eeaf-6630-4f50-b451-aa2b4d4cc680">
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's onComplete() callback
HomeViewController.promotionPublisherlet stored property (I'm assuming Omni.dataStack is the same as the global var dataStack declared in DataStack.swift)
UserViewModel.init(), specifically let userPublisher and let cartPublisher
Anything else that is calling methods on the dataStack that happens right after launch
@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's `onComplete()` callback
- `HomeViewController.promotionPublisher` `let` stored property (I'm assuming `Omni.dataStack` is the same as the global `var dataStack` declared in `DataStack.swift`)
- `UserViewModel.init()`, specifically `let userPublisher` and `let cartPublisher`
- Anything else that is calling methods on the `dataStack` that happens right after launch
Sorry, scratch that. I just noticed your error in the last screenshot is in the completion closure itself. The error code 259 implies the file already exists. Do you know where/when this file is being created?
@JohnEstropia commented on GitHub (Jul 5, 2024):
Sorry, scratch that. I just noticed your error in the last screenshot is in the `completion` closure itself. The error code `259` implies the file already exists. Do you know where/when this file is being created?
Sorry, scratch that. I just noticed your error in the last screenshot is in the completion closure itself. The error code 259 implies the file already exists. Do you know where/when this file is being created?
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
@imrobbyrc commented on GitHub (Jul 5, 2024):
> Sorry, scratch that. I just noticed your error in the last screenshot is in the `completion` closure itself. The error code `259` implies the file already exists. Do you know where/when this file is being created?
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 NSFileProtectionKey or NSPersistentStoreFileProtectionKey explicitly, so the default will be NSFileProtectionCompleteUntilFirstUserAuthentication. Does the same issue happen if the notifications arrive in the lockscreen AFTER the first device passcode entry?
@JohnEstropia commented on GitHub (Jul 5, 2024):
I see. CoreStore doesn't set any `NSFileProtectionKey` or `NSPersistentStoreFileProtectionKey` explicitly, so the default will be `NSFileProtectionCompleteUntilFirstUserAuthentication`. Does the same issue happen if the notifications arrive in the lockscreen AFTER the first device passcode entry?
I see. CoreStore doesn't set any NSFileProtectionKey or NSPersistentStoreFileProtectionKey explicitly, so the default will be NSFileProtectionCompleteUntilFirstUserAuthentication. Does the same issue happen if the notifications arrive in the lockscreen AFTER the first device passcode entry?
yes, as long as the device is locked it will be fail to initiate datastack
@imrobbyrc commented on GitHub (Jul 5, 2024):
> I see. CoreStore doesn't set any `NSFileProtectionKey` or `NSPersistentStoreFileProtectionKey` explicitly, so the default will be `NSFileProtectionCompleteUntilFirstUserAuthentication`. Does the same issue happen if the notifications arrive in the lockscreen AFTER the first device passcode entry?
yes, as long as the device is locked it will be fail to initiate datastack
how i can set data NSPersistentStoreFileProtectionKey and NSFileProtectionKey ? i see in source code it only let variable
@imrobbyrc commented on GitHub (Jul 5, 2024):
how i can set data `NSPersistentStoreFileProtectionKey` and `NSFileProtectionKey` ? i see in source code it only let variable
<img width="609" alt="Screenshot 2024-07-05 at 09 43 50" src="https://github.com/JohnEstropia/CoreStore/assets/25898417/6796e7f5-2afa-4d28-806f-5d566fb51c5b">
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
@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
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
@imrobbyrc 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
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
@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
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
@imrobbyrc 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
i think i will wait for SDK. thanks @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.)
@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.)
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
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.)