正在使用的代码如下
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[self performSelector:@selector(addContacts) withObject:nil afterDelay:0.1];
}
-(void)addContacts
{
sqlite3_stmt *statement;
const char *dbpath = [databasePath UTF8String];
if (sqlite3_open(dbpath, &contactDB) == SQLITE_OK)
{
NSString *insertSQL = [NSString stringWithFormat:
@"INSERT INTO CONTACTS (name, address, phone) VALUES (\"%@\", \"%@\", \"%@\")",
@"Anu", @"0009", @"Hyderabad"];
const char *insert_stmt = [insertSQL UTF8String];
sqlite3_prepare_v2(contactDB, insert_stmt,
-1, &statement, NULL);
if (sqlite3_step(statement) == SQLITE_DONE)
{
}
else {
}
sqlite3_finalize(statement);
sqlite3_close(contactDB);
}
else
{
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Information Alert"
message:@"Please enter the name "
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[message show];
}
}
但是当它在后台时它不起作用