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 trial

iOS

Self-Destructing Messaging App - Save in Background doesn't work if user goes back to camera

I'm testing out the Ribbit app, and when I send a picture, if I go right back to the camera then the message doesn't send and I see the friends list. Is there a way to make it send in the background but also allow for me to go straight back to the camera?

2 Answers

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

So the reason is that the view controller isn't reset ([self reset]) until the message is uploaded successfully. Since the save is happening in the background, if it takes longer than it takes you to go back to the camera, then the view controller hasn't been reset, which is why you don't see the camera. This is to prevent losing the image or video if uploading fails for some reason.

Any elegant solution will require a little more checking and storing things. Take Instagram, for example. If the upload fails, the message shows at the top of your feed with an option to try again. So with Ribbit, one solution would be to store the message locally in the app while it's uploading, reset the view controller, allow the user to access the camera for a new message, but still create an option for resending that message you're holding onto if it fails. Another solution would be to show a progress dialog or something to block actions until the upload finishes.

What I would do is embed all of the view controllers within the app in a parent view controller that observes a notification, say RIBMessageUploadedSuccessfully. When the notification is sent, the parent view controller can pop a modal (or just slide a bar down) on top of whatever the user is doing. You'll just need to fire the notification off once the upload is complete (and also write the message to disk as well).

You can also have other notifications as well for different statuses - RIBMessageFailedToUpload is another good option.

Ben Jakuben
Ben Jakuben
Treehouse Teacher

We really need to cover notifications! This is a good answer.