Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 19, 2008, 08:10 PM   #1
DaveGee
macrumors 6502a
 
Join Date: Jul 2001
Thread Events & NSURLConnections...

Okay here's a question thats gonna be kinda messy for me to explain but lemme try my best....

I have an app...

The app does (among other things the following)

1: Reads a few XML files

2: Connects synchronously to a device on my network using a soap call and parse some more XML data

3: Threads-out a thread that open an asynchronous connection to yet another soap service and just listens for XML status messages (this stays open until the app quits).

4: Displays a list of items (obtained by one of the many XML data parses) on the iPhone/iPod screen... and change the items listed as XML status messages come in from the async connection from step 3....

To my shock and amazement I got all this working and it doesn't crash -- not yet anyway! (lol).

I just got approved for the 'official iPhone development program' and I paid my 99 bucks and can FINALLY debug my app directly on my iPod touch (instead of just the simulator)... I did all the stuff needed to get my app moved over to my device and my app STILL works!! Happy Happy Joy Joy!

So on to my problem/question...

When my iPod touch got into 'sleep mode' (screen blanks) as near as I can tell my asynchronous connection gets torn down... I'm sure this is a battery saving thing and it's okay... but how where do I add code to my app to reconnect the asynchronous connection and more to the point, when the asynchronous connection was killed did the thread get terminated too?

I'm so new to cocoa I'm just not sure how/where to find the answers to my questions...

If anyone has any insight/advice/input I'm all ears!

Thanks in advance!

Dave
DaveGee is offline   0 Reply With Quote
Old Jul 2, 2009, 07:39 AM   #2
rafta2009
macrumors newbie
 
Join Date: Jul 2009
Hi DaveGee

The iApp I am developing is very similar to yours. But I have problem using NSThread (should do the connection to the XMLRPC in background)
Would you be so kind and post your code including NSThread here?
rafta2009 is offline   0 Reply With Quote
Old Jul 2, 2009, 07:48 AM   #3
parapup
macrumors 65816
 
parapup's Avatar
 
Join Date: Oct 2006
The thread doing async IO will not be killed after resume. If the connection is disconnected, the thread will receive some specific error on the file descriptor you are using to connect to the remote server. So your thread should have logic to detect connection errors and attempt a reconnection to the server.

Without seeing the code I am not sure how exactly you are doing the async IO - if you are using something like the select() system call which allows you to specify a timeout - you will get a timeout error after your thread resumes and you would need to select again - which will fail if the socket is disconnected and then you can initiate a reconnect - just an example.

On a regular Mac you could subscribe to power events and tear down your connection / mark it dead before the computer goes to sleep - not sure if same/similar API exists on the phone side.
parapup is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Notifications & All Day Events? Big Stevie iOS 7 2 Oct 26, 2013 12:00 PM
Locate deleted photos & events J0shyGill OS X 10.8 Mountain Lion 0 Oct 1, 2013 10:22 PM
Events in Reminders & Calendar App On Lockscreen All the Time? boba7523 iPhone Tips, Help and Troubleshooting 3 Jun 23, 2013 12:59 AM
FCP X projects & events between Macs on same hard drive? BDRhodes Digital Video 3 Mar 20, 2013 02:01 PM
Asynchronous NSURLConnections + NSTableView Help jwei92 Mac Programming 0 Jul 10, 2012 08:42 PM

Forum Jump

All times are GMT -5. The time now is 04:03 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC