Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在开发一个应用程序,我在其中使用 performSelectorInBackground 在后台执行一些同步任务。在我的代码中,我希望能够检测我是否在后台进程中运行。这样我可以防止可能出现的警报消息。
谢谢你的帮助!
马库斯
通过“后台进程”,我假设您的意思是“后台线程”。要检查您是否在主线程上运行,请尝试以下操作:
// Some error handling code if ([NSThread isMainThread]) { // Provide some sort of UI feedback } else { // Send a message to the main thread to provide feedback }