如何在iOS中创建后台线程,该后台线程在app被隐藏后继续运行

时间:2022-09-02 09:57:41

I am new to iPhone development and working through SamsTechYourself iPhone Development. I am trying to write an app that receives push notifications from an MQTT broker (similar to Facebook Messenger).

我对iPhone的开发并不熟悉,也不熟悉SamsTechYourself iPhone的开发。我正在编写一个应用程序,它接收来自MQTT代理(类似于Facebook Messenger)的推送通知。

I have compiled a C library called libmosquitto and have it running on the emulator, however I am stuck trying to figure out how to make it continue to listen for notifications, while the app is in the background. My book mentions modes for VOIP and background sounds but does not go into much detail.

我已经编译了一个C库,名为lib蚊子,并让它在模拟器上运行,但我仍在试图弄清楚如何让它在后台继续监听通知。我的书中提到了VOIP和背景音的模式,但没有详细说明。

Could anyone point me to a good tutorial in iPhone and background processes or gives me some tips on how to get started?

有没有人能给我推荐一个关于iPhone和背景流程的好教程,或者给我一些如何开始的建议?

What I want is a twitter like app, which gives a little popup info when a new message has been pushed from the broker.

我想要的是一个类似twitter的应用程序,当一个新的消息从代理推送出去时,它会提供一个小的弹出信息。

1 个解决方案

#1


2  

You can't do exactly what you are trying to do (run a background process, listen for notifications). All background notifications on iOS are handled through Apple Push Notification Services (APNS). In short, you need to setup a server to send messages through APNS and APNS will notify the user that something has happened. The user can then choose to open your app.

你不能做你想做的事情(运行后台进程,监听通知)。iOS上的所有后台通知都是通过Apple Push Notification Services (APNS)处理的。简而言之,您需要设置一个服务器,以便通过APNS发送消息,而APNS将通知用户发生了什么事情。用户可以选择打开你的应用。

http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html

http://developer.apple.com/library/ios/文档/ NetworkingInternet /概念/ RemoteNotificationsPG / ApplePushService / ApplePushService.html

#1


2  

You can't do exactly what you are trying to do (run a background process, listen for notifications). All background notifications on iOS are handled through Apple Push Notification Services (APNS). In short, you need to setup a server to send messages through APNS and APNS will notify the user that something has happened. The user can then choose to open your app.

你不能做你想做的事情(运行后台进程,监听通知)。iOS上的所有后台通知都是通过Apple Push Notification Services (APNS)处理的。简而言之,您需要设置一个服务器,以便通过APNS发送消息,而APNS将通知用户发生了什么事情。用户可以选择打开你的应用。

http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html

http://developer.apple.com/library/ios/文档/ NetworkingInternet /概念/ RemoteNotificationsPG / ApplePushService / ApplePushService.html