在后台线程中使用FMDatabaseQueue
FMDatabaseQueue *queue = [FMDatabaseQueue databaseQueueWithPath:[self dbPath]];
queue inTransaction:^(FMDatabase *db) {
for (NSDictionary *propertyValueDictionary in customers) {
NSString *customerId = [propertyValueDictionary objectForKey:@"CustomerId"];
NSString *property = [propertyValueDictionary objectForKey:@"Property"];
NSString *value = [propertyValueDictionary objectForKey:@"Value"];
BOOL deleted = [[propertyValueDictionary objectForKey:@"Deleted"] boolValue];
NSString *revision = [propertyValueDictionary objectForKey:@"Revision"];
NSString *sql = @"INSERT OR REPLACE INTO Customer (CustomerId, Property, Value) VALUES (?, ?, ?);";
[db executeUpdate:sql, customerId, property, value];
}
}];
同时,我想在主线程中读/写sqlite而不会延迟并阻止UI。
任何解决方案?提前谢谢。