当前位置: 动力学知识库 > 问答 > 编程问答 >

iphone - Database updating in background is problematic

问题描述:

I have to store some data into database after downloading it from server,I have succesfully downloaded the data ,but when i go to update it into sqlite database it takes time. In that case if user keeps the app is background and after sometimes user brings back the app in foreground then after few minutes it got crashed.

When user brings back the app in foreground then it takes high time to load the same screen where user has left it,and before the screen appears app got crashed.

Please help me on this....how can I keep this process running in background as well as foreground without any issues.

网友答案:

Try this:

[self performSelectorInBackground:@selector(dataBaseUpdateMethod:)
                       withObject:dictForUpdatingTheDatabase];

Where, dataBaseUpdateMethod will be the method which updates the database & dictForUpdatingTheDatabase is the NSDictionary Object (or say any other object of any type).

Hope this helps.

网友答案:

update your sqlite database in a background thread (using performSelectorInBackground).

if you are updating it in main thread in that case when user trying to app in foreground then application main thread is busy to complete your update DB task and not able to load the application and cause a crash.

网友答案:

Use This:

[self performSelectorInBackground:@selector(updateDB:) withObject:dictionary];
分享给朋友:
您可能感兴趣的文章:
随机阅读: