Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialNick Sint
4,208 PointsFrontend Communicating With Backend Offline?
My question is with regards to the Ribbit App. I understand how the communication between the frontend with the backend (parse) works when sending messages; however, what if the user is in an area without network connection?
How would the code have to be modified in order to create some sort of "outbox" (similar to emails) whereby the user's messages will be sent (i.e. the query/save actions be executed) when the user's device is next connected to a network?
1 Answer
Stone Preston
42,016 Pointsyou would need to check for an internet connection before you send the message. you can do this using something like reachability. then if there is no internet connection you would need to save the message data on disk if you wanted it to persist between app opens and closes. you can use the NSNotification methods of reachability to notify any objects of network interface changes, so you can use that to check to see if the user now has network connection. if they do, send the messages that are in the "outbox".
However, I would think it would probably be best to just display a little message that says "No Internet Connection" and not even bother with all that. Thats what apps like instagram and snapchat do when you dont have internet. they just provide a message