1

I have developed socket.IO for iOS Application . When app is running, app can send and receive http socket data without any problem .

All i want to do , I want to get messages when app get in background.

I think appdelegate.h 's delegate method :

- (void)applicationDidEnterBackground:(UIApplication *)application

works for it . But how can i implement my function in that scope ?

Onder OZCAN
  • 1,556
  • 1
  • 16
  • 36
  • Sorry but that link provides only a few options . What i am asking it , working with HTTP - Socket in background . If answer is no , how facebook-chat or other IM app's work with like that ? – Onder OZCAN Sep 07 '13 at 14:37

2 Answers2

1

In case you are using GCDAsyncSocket for socket communication, you will receive a call back in the below method even if your application is in background.

- (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag

Update: May be I was able to receive message on my socket because my application was VoIP & apple allows background activity for my application.

thatzprem
  • 4,697
  • 1
  • 33
  • 41
  • Prem , yes , You are able to receive message , because VOIP allowed in background by apple. But I need to build APN service btw . :) – Onder OZCAN Sep 09 '13 at 06:22
1

In iOS, no app has unlimited background working permissions except the VOIP apps, the navigation apps or the music apps(unless your app is one interfacing with some external hardwares via bluetooth). They can only work for a particular amount of time, after which, they enter into the suspended state.

Now as far as your comment asks about the IM apps, they use Apple Push Notification Services to notify the user of any important event and thus they handle that data at any time irrespective of the suspension time.

For eg., Facebook lets you know of any incoming message via push notification. When you open the app from that, your appDelegate's applicationDidFinishLaunchingWithOptions: method gets called which has the argument containing the information your push notification intended it to have. You can have a look at the push notification services documentations on Apple website here. Also there is a good tutorial of it on Ray Wenderlich.

Zen
  • 3,047
  • 1
  • 20
  • 18
  • Zen , I just read about APN services, But they all said, your message has no guarantee for arrive to device , is that true ? They do not give %100 chance .. – Onder OZCAN Sep 08 '13 at 00:00
  • Yeah, push notifications are 100% guaranteed to reach the user's device. It can be due to a few reasons like the user's phone is turned off or their network doesn't allow the port to the APNS server to communicate. But these are extreme cases. Suppose if Apple allowed your app background processing, the phone can be turned off in that case too or the network is not allowing your app to download data. So figure out a work around for those cases and use the best thing they are allowing and providing you. – Zen Sep 08 '13 at 06:05