1
votes

I'm looking into using the Channel API to push messages to my iOS client. I haven't completely wrapped my head around it, but the only way would be to use a hidden UIWebView that triggers an Objective-C method.

Would this work? To have a hidden UIWebView listening to channel messages? How would the web view be notified of new messages by the channel? How would I trigger an Objective-C method when a new message is received, such as an alert saying "You've received a new message."?

Are there any downsides to this approach?

2

2 Answers

3
votes

I'm doing the opposite. I'm using Urban Airship to send iOS notifications to my iOS app, which is really an iOS wrapper around a UIWebView.

GAE Channels aren't particularly robust in my experience, I've noticed messages not get sent, especially when you have to re-establish a connection. I wonder if the UIWebView connection will get disconnected when the app goes to the background.

0
votes

I'm doing what you are asking. There are two things you need to be able to do: make calls from Objective-C into the UIWebView, and get events from the UIWebView to call back in to Objective-C. To do the first you call UIWebView's "stringByEvaluatingJavaScriptFromString" method. To call back into Objective-C, you register a web view delegate, and then in the "shouldStartLoadWithRequest" method you look for a "fake" protocol (e.g. "js-callback" or something like that) so that in your javascript you navigate an iframe to "js-callback:informationForObjectiveCToOperateOn". This blog post explains the procedure: http://blog.techno-barje.fr/post/2010/10/06/UIWebView-secrets-part3-How-to-properly-call-ObjectiveC-from-Javascript/.