0

我正在开发一个应用程序,我在其中使用 performSelectorInBackground 在后台执行一些同步任务。在我的代码中,我希望能够检测我是否在后台进程中运行。这样我可以防止可能出现的警报消息。

谢谢你的帮助!

马库斯

4

1 回答 1

2

通过“后台进程”,我假设您的意思是“后台线程”。要检查您是否在主线程上运行,请尝试以下操作:

// Some error handling code
if ([NSThread isMainThread]) {
    // Provide some sort of UI feedback
}
else {
    // Send a message to the main thread to provide feedback
}
于 2010-05-02T10:24:25.583 回答