1

I'm new to IOS development and recently I'm designing an app that can be remote controlled by another user via wifi.

I'm thinking of implementing it like a "chat app", like when it receive a message like "stop the current music" it'll do so. But what if the app is running in the background? I searched SO and find when using didReceivingRemoteNotification, the user has to tap "view" to call the function. What if I want to make it happen automatically?

By the way, if my app is running in the bg, and it has connected to another device using NSNetService or somewhat, will the connnection stop?

Marcos Aguayo
  • 6,840
  • 8
  • 28
  • 61
DrustZ
  • 342
  • 1
  • 5
  • 19

2 Answers2

0

You can get control in didReceivingRemoteNotification when app in background mode by using silent push notification for that you have to send notification as bellow

$body['aps'] = array(
    'content-available' => 1,
.........
    'other_params' => 'value'
    );

It will invoke app and call didReceivingRemoteNotification even if it is background mode. But this will work from IOS7 onward.

Rajesh
  • 948
  • 7
  • 13
0

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...

Community
  • 1
  • 1
Michael
  • 6,451
  • 5
  • 31
  • 53
  • thank for giving suggestions, here's a point that I still don't understand : does that mean in IOS7 or higer version, the app WILL receive remotenotification in background? – DrustZ Aug 23 '14 at 10:11
  • @Zmr_祥生 yes it does usually. you cannot however open the app when you received a notification. The user still has to tap on the badge to open the app. But you can handle the notification in other ways, e.g. to download the chat-message, download the received image, or whatever. There is one exception though: if the user kills the app intentionally, your app will get no more notifications until the user opens the app again. the device can still receive push notifications in this case, but its like iOS 6 and earlier: a badge is shown but the app isn't notified until the user opens it. – Michael Aug 23 '14 at 10:28