我是IOS开发的新手,最近我正在设计一个可以由另一个用户通过wifi远程控制的应用程序。
我正在考虑将其实现为“聊天应用程序”,例如当它收到“停止当前音乐”之类的消息时,它会这样做。但是如果应用程序在后台运行呢?我搜索了SO并发现使用时didReceivingRemoteNotification
,用户必须点击“查看”才能调用该功能。如果我想让它自动发生怎么办?
顺便说一句,如果我的应用程序在 bg 中运行,并且它已使用 NSNetService 或其他方式连接到另一台设备,连接会停止吗?
我是IOS开发的新手,最近我正在设计一个可以由另一个用户通过wifi远程控制的应用程序。
我正在考虑将其实现为“聊天应用程序”,例如当它收到“停止当前音乐”之类的消息时,它会这样做。但是如果应用程序在后台运行呢?我搜索了SO并发现使用时didReceivingRemoteNotification
,用户必须点击“查看”才能调用该功能。如果我想让它自动发生怎么办?
顺便说一句,如果我的应用程序在 bg 中运行,并且它已使用 NSNetService 或其他方式连接到另一台设备,连接会停止吗?
当应用程序处于后台模式时,您可以通过使用静默推送通知来控制 didReceivingRemoteNotification,因为您必须发送通知如下
$body['aps'] = array(
'content-available' => 1,
.........
'other_params' => 'value'
);
即使是后台模式,它也会调用 app 并调用 didReceivingRemoteNotification。但这将从 IOS7 开始起作用。
For iOS 7 you have "background notification fetch". See this question for details. In iOS 6 or earlier, what you ask for is not really possible.
You cannot open the app automatically when you receive a push notification. But you can download additional information when receiving a push notification, so that when the user taps the notification later its content is already loaded into the app.
However, if the user force-quits the app, your app is not notified at all about the push notification. Only when the user taps the notification badge, the app will be opened, in this case.
Maybe also helpful...
didReceiveRemoteNotification: