Code, Code, Revolution!
Ever been in a situation where you need to wait for an asynchronous task to complete. This is a rare case but sometimes you need to do this. I used this techinque in my previous post on how to extract the user-agent string from a UIWebView. Check it out for a more complete sample.
The trick is to use NSRunLoop which allows you to access the applications run loop. runMode:beforeDate allows you to execute one loop at the time so calling this in a while loop you can wait for something to complete and then move on. Here’s a sample:
int i = 0;
while (i < 10)
{
// This executes another run loop.
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
i++;
}This will execute/wait 10 run loops before moving on. Obviously this is a retarded sample because it has no real use. What you might want to do is wait for a UIWebView to execute a request or for a NSMutableURLRequest to complete. Yes, NSURLRequest has a synchronous mode but that doesn’t allow for delegate methods to execute. If you don’t understand why you would won’t to do this, DON’T DO IT!
In each new version of iOS the browser gets a new user-agent string. I’ve been searching for a way to get the user-agent string from the API but haven’t been able to find a straight forward way to do it. Here’s my solution:
» Find the solution here..
I’m working on a new application that will be released on Appstore sometime soon and the full source will be posted on this blog, but I want to share a part of my application already.
I want to restrict access to my application using some kind of password and I really like the pattern style unlock screen found on the Android. If you are a total iPhone nerd/geek and don’t know what I am talking about, check out this clip:
The clip showcase an Android style unlock screen on iPhone available for jailbreaked devices through Cydia. I’ve recorded the sample app I am presenting here as well. I think you can appreciate the similarities between the Cydia app and my app:
Do note however that this is not an unlock screen for the phone itself, it’s a password function for your app.
DnBNor Eiendom, one of Norways largest real estate broker, joins the iPhone train today with the release of their location aware app “Finn din Bolig“. Building on the successful application “Hitta Hem” released by Svensk Fastighetsförmedling little over a year ago.
The application utilize the GPS functionality and finds homes, appartments and vaccation cabins for sale on www.dnbnoreiendom.no close to the devices’ location. It’s available in iTunes App Store Norway, Sweden, Denmark and Finland. Localized in Norwegian, Swedish and English.
Just like for the Hitta Hem release there’s a YouTube video showcasing the application inspired by Apples’ own advertisement.
Back-end technology used to power the application: Microsoft SQL Server 2005, .NET 3,5, Windows Comunication Foundation, EPiServer CMS 4.
This is the second iPhone application I’ve built at Avantime release on app store, and more applications are in the works!
If you’re building a somewhat complex NET TV application with multiple views and want an application like feeling you probably want to allow users to use the back button on the remote to navigate but still control the navigation paths instead of the default “web style” back functionality which makes absolutely no sense in an application. The problem is that if you hook the key event for the back button and redirect the user yourself you also make it impossible to get out of your application and back to the NET TV portal, well, not impossible, you can still hit the “Net tv”-button to get there. Still, the Philips engineers won’t appreciate this.
The solution is very simple. Using javascript you can pass the browser back and forward using the “window.history” object. When you want to close your application and send the user back to the portal screen, just call:
<script type="text/javascript"> // <![CDATA[ window.history.go(-1000000); // ]]> </script>
Pass the user one million pages back, unless the user has visited one million pages in your application he will end up on the NET TV-portal
Are you too having problems updating your iPhone to OS 4.0 beta and iTunes crash while showing the message “Verifying iPhone update with Apple”? Use restore instead!
Also, it is possible to downgrade from iPhone OS 4.0 to 3.1.3 using the restore function and a firmware image for 3.1.3. The baseband however will not be downgraded.
Today Apple presented what will come later this summer, iPhone OS 4.0. Multitasking has been a long awaited and talked about feature that I’m not the only one being excited about, I was not so excited however to find out that it’s not supported on iPhone 3G! The new multitasking feature looks really neat and the tray is integrated nicely with the OS.
Multitasking is implemented using different services. It’s still unclear to me what limitations this has on freedom to develop whatever. Apple demo’ed Pandora’s Internet radio streaming app, iPhone OS 4.0 will allow apps like it to play music in the background, with playback controls available even at the lock screen. They also demo’ed Skype (VoIP), which utilize the VoIP service to continue to receive calls even when it is not the foreground app, LOVELY! A third mechanism is a new direction feature which calculate the device location from cellular towers instead of using battery draining GPS. Awesome for applications that don’t really need GPS accuracy. A fourth and fifth enhancement relates to Apple’s existing push notification service and a new “local notifications” service that allows apps to post reminders or other events without using Apple’s servers.
A sixth feature, task completion, will enable an app to start a job and continue working on it after the user leaves the app. And example given cited an app posting photos to Flicker, which continued working after the user left that app.
The seventh multitasking mechanism is fast app switching, which “allows you to restore the state of an app when you switch out and back,” is the easiest to implement, essentially freezing the progress of an app such as a game while the user handles another task in another app.
Interesting and annoying sidenote. While trying to update my iPhone to iPhone OS 4.0 beta iTunes keep crashing when trying to “Verifying iPhone update with Apple…”. Pesky!
If you want to read about todays iPhone OS 4.0 event, head over to Engadget: http://www.engadget.com/2010/04/08/live-from-apples-iphone-os-4-event/
If you found this post it’s likely you’re interested in finding a cheap (most likely free) CDN. There are numerous posts on the net about using Googles’ App Engine as a free CDN. It’s important to understand what a true CDN is. Definition of a CDN from Wikipedia:
A content delivery network or content distribution network (CDN) is a system of computers containing copies of data, placed at various points in a network so as to maximize bandwidth for access to the data from clients throughout the network. A client accesses a copy of the data near to the client, as opposed to all clients accessing the same central server, so as to avoid bottleneck near that server.
Content types include web objects, downloadable objects (media files, software, documents), applications, real time media streams, and other components of internet delivery (DNS, routes, and database queries).
App Engine does spread files to different geographically located servers however, Google doesn’t provide any information about their content delivery network. Just Ping has a tool that ping/resolve domain names at 41 different locations in the world. Looking at this URL my App Engine domain resolves to 12 different IP addresses over the world! In this sense Google App Engine is a real content delivery network, but that is not the primary focus of the service. How well does App Engine perform and how can you leverage it »
With this blog I try to provide useful tips and solutions for programming .NET, Objective-C and more. My name is Björn Sållarp, and I love writing code.