CoreData: error: (778) I/O error for database ? How to handle this error? - ios

I'm getting a Core data error when my app is in open state with lock screen mode.
My code:
func savePesistenceContext() {
//try! self.dataStack.mainContext.save()
do {
try self.dataStack.mainContext.save()
} catch {
let nserror = error as NSError
debugPrint("savePesistenceContext", nserror)
}
}
Error:
CoreData: error: SQLCore dispatchRequest: exception handling request: <NSSQLSaveChangesRequestContext: 0x280697540> , I/O error for database at /var/mobile/Containers/Data/Application/6EBC7CD6-9299-431A-A24A-1F6FA86792BD/Documents/Coral.sqlite. SQLite error code:778, 'disk I/O error' with userInfo of {
NSFilePath = "/var/mobile/Containers/Data/Application/6EBC7CD6-9299-431A-A24A-1F6FA86792BD/Documents/Coral.sqlite";
NSSQLiteErrorDomain = 778;
}
CoreData: error: (778) I/O error for database at /var/mobile/Containers/Data/Application/6EBC7CD6-9299-431A-A24A-1F6FA86792BD/Documents/Coral.sqlite. SQLite error code:778, 'disk I/O error'
Error Domain=NSCocoaErrorDomain Code=256 "The file “Coral.sqlite” couldn’t be opened." UserInfo={NSFilePath=/var/mobile/Containers/Data/Application/9AB16F39-8933-4A75-AB6A-59CBBCC42A4F/Documents/Coral.sqlite, NSSQLiteErrorDomain=23}
When will this error come and how can we resolve this error?

Related

SKReceiptRefreshRequest always fails in Xcode 12.2 with .storekit configuration file

When I run the app with .storekit configuration file in Xcode 12.2 / iOS 14.2 Simulator, my SKReceiptRefreshRequest always fails, I get an error in my func request(_ request: SKRequest, didFailWithError error: Error) delegate method. Here are the logs:
# Printed by some Apple internal framework:
<SKReceiptRefreshRequest: 0x60000320d640>: Finished refreshing receipt with error: Error Domain=ASDServerErrorDomain Code=5002 "Unhandled exception" UserInfo={NSLocalizedDescription=Unhandled exception, NSLocalizedFailureReason=An unknown error occurred}
# Error logged by my code:
Failed to refresh app receipt: Error Domain=SKErrorDomain Code=0 "UNKNOWN_ERROR" UserInfo={NSLocalizedDescription=UNKNOWN_ERROR, NSUnderlyingError=0x600003c9a040 {Error Domain=ASDServerErrorDomain Code=5002 "Unhandled exception" UserInfo={NSLocalizedDescription=Unhandled exception, NSLocalizedFailureReason=An unknown error occurred}}}
I run the request as usual:
class ReceiptFetcher: NSObject {
func fetchReceipt() {
let request = SKReceiptRefreshRequest(receiptProperties: nil)
request.delegate = self
request.start()
}
}
extension ReceiptFetcher: SKRequestDelegate {
func requestDidFinish(_ request: SKRequest) {
LogVerbose("App receipt refreshed!")
// Handling success
}
func request(_ request: SKRequest, didFailWithError error: Error) {
LogVerbose("Failed to refresh app receipt: \(error)")
// Handling error
}
}
Everything worked fine until I upgraded Xcode to 12.2. Now it fails for both Run and Test actions.
I found nothing about ASDServerErrorDomain with code 5002. Any help on that?
Everything works again since Xcode 12.4. I hope they won't break this thing again...

The operation couldn’t be completed. (NSURLErrorDomain error -1011.)

I'm trying to upload an image to a FTP server using swift 4
I used FileProvider which is a library for Ftp connection iOS
anyway I'm checking the provider is reachable. and Im getting this error
The operation couldn’t be completed. (NSURLErrorDomain error -1011.)
this is the full error object:
Error Domain=NSURLErrorDomain Code=-1011 "(null)" UserInfo={NSErrorFailingURLKey=ftp://xxxx.xxxx.xxxx.xxxx:21/, NSErrorFailingURLStringKey=ftp://xxxx.xxxx.xxxx.xxxx:21/, NSURL=ftp://xxxx.xxxx.xxxx.xxxx:21/}
this is my code:
self.ftpProvider!.isReachable { (flag, error) in
if flag {
print("RIZK:--- provider is reachable ")
let progress = self.ftpProvider!.copyItem(localFile: localURL, to: "/files/\(imageName)", overwrite: true, completionHandler: { (error) in
if error == nil {
print("RIZK:-- Ready to upload")
}else{
print("RIZK:--\(error?.localizedDescription ?? "")")
}
})
print(progress?.fractionCompleted ?? 0)
}else{
print("RIZK:--- provider not reachable, with error \(error?.localizedDescription ?? "") ")
}
}

How to perform migration when changed relationship from many to one?

This is what I have in source model for Business entity:
and this is what I have in destnation model for Business entity:
As you can see I changed relationship from many to one, from users to user.
But now I have the following error:
URL:file:///private/var/mobile/Containers/Shared/AppGroup/00C2A6C6-8149-4CF7-95E1-6ABD8A2B3B57/POSowner.sqlite options:{
NSInferMappingModelAutomaticallyOption = 1;
NSMigratePersistentStoresAutomaticallyOption = 1;
} ... returned error Error Domain=NSCocoaErrorDomain Code=134110 "An error occurred during persistent store migration." UserInfo={sourceURL=file:///private/var/mobile/Containers/Shared/AppGroup/00C2A6C6-8149-4CF7-95E1-6ABD8A2B3B57/POSowner.sqlite, reason=Cannot migrate store in-place: Validation error missing attribute values on mandatory destination relationship, destinationURL=file:///private/var/mobile/Containers/Shared/AppGroup/00C2A6C6-8149-4CF7-95E1-6ABD8A2B3B57/.POSowner.sqlite.migrationdestination_41b5a6b5c6e848c462a8480cd24caef3, NSUnderlyingError=0x170458990 {Error Domain=NSCocoaErrorDomain Code=134110 "An error occurred during persistent store migration." UserInfo={entity=Business, attribute=user, reason=Validation error missing attribute values on mandatory destination relationship}}} with userInfo dictionary {
NSUnderlyingError = "Error Domain=NSCocoaErrorDomain Code=134110 \"An error occurred during persistent store migration.\" UserInfo={entity=Business, attribute=user, reason=Validation error missing attribute values on mandatory destination relationship}";
destinationURL = "file:///private/var/mobile/Containers/Shared/AppGroup/00C2A6C6-8149-4CF7-95E1-6ABD8A2B3B57/.POSowner.sqlite.migrationdestination_41b5a6b5c6e848c462a8480cd24caef3";
reason = "Cannot migrate store in-place: Validation error missing attribute values on mandatory destination relationship";
sourceURL = "file:///private/var/mobile/Containers/Shared/AppGroup/00C2A6C6-8149-4CF7-95E1-6ABD8A2B3B57/POSowner.sqlite";
}
fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=134110 "An error occurred during persistent store migration." UserInfo={sourceURL=file:///private/var/mobile/Containers/Shared/AppGroup/00C2A6C6-8149-4CF7-95E1-6ABD8A2B3B57/POSowner.sqlite, reason=Cannot migrate store in-place: Validation error missing attribute values on mandatory destination relationship, destinationURL=file:///private/var/mobile/Containers/Shared/AppGroup/00C2A6C6-8149-4CF7-95E1-6ABD8A2B3B57/.POSowner.sqlite.migrationdestination_41b5a6b5c6e848c462a8480cd24caef3, NSUnderlyingError=0x170458990 {Error Domain=NSCocoaErrorDomain Code=134110 "An error occurred during persistent store migration." UserInfo={entity=Business, attribute=user, reason=Validation error missing attribute values on mandatory destination relationship}}}: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-800.0.58.6/src/swift/stdlib/public/core/ErrorType.swift, line 178
2016-11-30 14:25:43.070185 POSowner[3474:513840] fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=134110 "An error occurred during persistent store migration." UserInfo={sourceURL=file:///private/var/mobile/Containers/Shared/AppGroup/00C2A6C6-8149-4CF7-95E1-6ABD8A2B3B57/POSowner.sqlite, reason=Cannot migrate store in-place: Validation error missing attribute values on mandatory destination relationship, destinationURL=file:///private/var/mobile/Containers/Shared/AppGroup/00C2A6C6-8149-4CF7-95E1-6ABD8A2B3B57/.POSowner.sqlite.migrationdestination_41b5a6b5c6e848c462a8480cd24caef3, NSUnderlyingError=0x170458990 {Error Domain=NSCocoaErrorDomain Code=134110 "An error occurred during persistent store migration." UserInfo={entity=Business, attribute=user, reason=Validation error missing attribute values on mandatory destination relationship}}}: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-800.0.58.6/src/swift/stdlib/public/core/ErrorType.swift, line 178
and I do not know what to do to workaround that issue. Any ideas?
This is how I setup core data stack:
static func mr_setupCoreDataStack() {
guard NSPersistentStoreCoordinator.mr_default() == nil else {
return
}
let managedObjectModel = NSManagedObjectModel.mr_default()
let persistentStoreCoordinator = NSPersistentStoreCoordinator(managedObjectModel: managedObjectModel!)
var storePath = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: SharedGroupName)
storePath = storePath!.appendingPathComponent("POSowner.sqlite")
let options = [NSMigratePersistentStoresAutomaticallyOption: true, NSInferMappingModelAutomaticallyOption: true]
try! persistentStoreCoordinator.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: storePath, options: options)
NSPersistentStoreCoordinator.mr_setDefaultStoreCoordinator(persistentStoreCoordinator)
NSManagedObjectContext.mr_initializeDefaultContext(with: persistentStoreCoordinator)
}
The simplest solution is to remove current database and allow MagicalRecord create a new one without any migrations. Remember to do it only ONCE.
static func mr_setupCoreDataStack() {
var storePath = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: SharedGroupName)
storePath = storePath!.appendingPathComponent("POSowner.sqlite")
try! FileManager.default.removeItem(at: storePath!)
}

I'm unable to get Deep linking to respond in the swift iOS simulator

So I'm trying to get FB and Twitter to respond from tappin on a table cell:
I set up the plist:
Then I created this function:
func schemeAvailable(scheme: String) -> Bool {
if let url = URL(string: scheme) {
return UIApplication.shared.canOpenURL(url)
}
return false
}
Then I tried to use it:
print(UIApplication.shared.canOpenURL(URL(string: "fb:")!))
if(schemeAvailable(scheme: "fb://")){
print("facebook agailable")
}
if(schemeAvailable(scheme: "twitter://")){
print("twitter agailable")
}
and get back a response of:
2016-10-03 17:04:09.096 JSONTesting[73245:2492124] -canOpenURL: failed for URL: "fb:" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"
false
2016-10-03 17:04:09.097 JSONTesting[73245:2492124] -canOpenURL: failed for URL: "fb://" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"
2016-10-03 17:04:09.098 JSONTesting[73245:2492124] -canOpenURL: failed for URL: "twitter://" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"
I've tried with and without the // in the string but to no avail...get the same error back every time.
Thanks

CoreData Swift : Crash : SQLite error code:14, 'unable to open database file'

I'm using swift 2.0 with Xcode 7.
I want to store names from a JSON file in CoreData.
I succeed to save datas in my CoreData model, but after the value number 1272 or 1273, my app crashes.
Here is the code :
for (key,subJson):(String, JSON) in json {
if let name = subJson["nom"].string {
print("key : \(key)")
self.savePerson(name)
}
}
func savePerson(name: String) {
let appDelegate =
UIApplication.sharedApplication().delegate as! AppDelegate
let managedContext = appDelegate.managedObjectContext
let entity = NSEntityDescription.entityForName("Person",
inManagedObjectContext:
managedContext)
let person = NSManagedObject(entity: entity!,
insertIntoManagedObjectContext:managedContext)
person.setValue(name, forKey: "name")
do {
try AppDelegate().managedObjectContext.save()
} catch {
fatalError("Failure to save context: \(error)")
}
people.append(person)
}
I tried to see with a breakpoint, and here is the program at the key 1272 or 1273 :
--> [savePerson()] try AppDelegate().managedObjectContext.save()
--> [AppDelegate] lazy var managedObjectContext: NSManagedObjectContext =
--> [AppDelegate][managedObjectContext] let coordinator = self.persistentStoreCoordinator
And here is the crash!
I checked and the name does exist, it's not nil.
I tried to put a kind of sleep on my code and it's not always at the same moment. Do you think this is a question of speed ?
Else, do you know why ?
The log is :
CoreData: error: (14) I/O error for database at /.../.../.../SingleViewCoreData.sqlite. SQLite error code:14, 'unable to open database file'
2015-09-22 23:59:59.774 testAlamofire2[8765:351886] CoreData: error: Encountered exception I/O error for database at /.../.../.../SingleViewCoreData.sqlite. SQLite error code:14, 'unable to open database file' with userInfo {
NSFilePath = "/.../.../.../.../SingleViewCoreData.sqlite";
NSSQLiteErrorDomain = 14;
} while checking table name from store: <NSSQLiteConnection: 0x7f8e2d677ee0>
2015-09-22 23:59:59.779 testAlamofire2[8765:351886] CoreData: error: -addPersistentStoreWithType:SQLite configuration:(null) URL:file:///.../.../.../.../SingleViewCoreData.sqlite options:(null) ... returned error Error Domain=NSCocoaErrorDomain Code=256 "(null)" UserInfo={NSSQLiteErrorDomain=14, NSUnderlyingException=I/O error for database at .../.../.../SingleViewCoreData.sqlite. SQLite error code:14, 'unable to open database file'} with userInfo dictionary {
NSSQLiteErrorDomain = 14;
NSUnderlyingException = "I/O error for database at /.../.../...SingleViewCoreData.sqlite. SQLite error code:14, 'unable to open database file'";
}
2015-09-22 23:59:59.780 testAlamofire2[8765:351886] Unresolved error Error Domain=YOUR_ERROR_DOMAIN Code=9999 "Failed to initialize the application's saved data" UserInfo={NSLocalizedDescription=Failed to initialize the application's saved data, NSLocalizedFailureReason=There was an error creating or loading the application's saved data., NSUnderlyingError=0x7f8e2d6772d0 {Error Domain=NSCocoaErrorDomain Code=256 "(null)" UserInfo={NSSQLiteErrorDomain=14, NSUnderlyingException=I/O error for database at /.../.../.../SingleViewCoreData.sqlite. SQLite error code:14, 'unable to open database file'}}}, [NSLocalizedDescription: Failed to initialize the application's saved data, NSLocalizedFailureReason: There was an error creating or loading the application's saved data., NSUnderlyingError: Error Domain=NSCocoaErrorDomain Code=256 "(null)" UserInfo={NSSQLiteErrorDomain=14, NSUnderlyingException=I/O error for database at /.../.../.../.../SingleViewCoreData.sqlite. SQLite error code:14, 'unable to open database file'}]
EDIT :
I found this page, I don't know if it helps. (old)
I think the problem may be because your save statement is creating a new instance of the application delegate, each time you save a new person:
try AppDelegate().managedObjectContext.save()
Try using the same, existing, instance that you use earlier:
try managedContext.save()

Resources