Timing Out An Application Due To Inactivity

In the recent months, I have had a few separate applications that required a “timeout”. What I mean by this is, the application should log the user out if they haven’t touched the screen in X number of minutes. There are quite a few uses for this, but the best use is when you have an application that contains sensitive data in a shared environment.

For example, say your company uses iPads to collect feedback from your customers. You would definitely want a timeout on the application in case a non-employee picked up a stray iPad.

The code that I came up with to do this is pretty simple, and I wanted to share it with you as well as walk you through an example of using it.

Overview

Here’s how it works. I have created a subclass of UIApplication called ELCUIApplication. The purpose of extending UIApplication was to overwrite the sendEvent: method. This method gets called every time there’s a touch. The touch could be on a button, text field, or just anywhere inside the window.

Inside of my sendEvent: method, I first call the super method (to ensure that we pass the tap through to do what it’s supposed to do), and then reset an NSTimer. This timer is set to go off after 5 minutes (configurable).

Once the timer does go off (the app times out), I fire off an NSNotification and everyone who subscribes to it will get notified. Pretty simple.

In order to reset the timer (perhaps after the user re-logs-in), you call the resetIdleTimer method of ELCUIApplication.

The main question you might ask is, why not just add a UIGestureRecognizer on the main window. This was my first thought, and after trying it for quite some time, I couldn’t get all of the taps to forward. This resulted in loss of functionality/interaction.

The project is available on github along with a sample project. Make sure you go there and at least download ELCUIApplication.h and ELCUIApplication.m before continuing.

Using Our Custom UIApplication Subclass

Drag ELCUIApplication.h and ELCUIApplication.m into your project. Make sure you check to copy them into your source folder. Now, open up main.m (I’ll bet you have never opened this file on purpose before). Update it to look like this:

#import <UIKit/UIKit.h>
 
int main(int argc, char *argv[])
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, @"ELCUIApplication", nil);
    [pool release];
    return retVal;
}

The only change we made is, we set the 3rd argument of UIApplicationMain to be an NSString with our classname (ELCUIApplication). This tells the app to start using our UIApplication rather than the super class.

One other thing to note is, in ELCUIApplicaiton.h there is a define called kApplicationTimeoutInMinutes. Change this value to modify the number of minutes until your application times out. By default, it’s set to 5.

That’s all that must be done to have your application start publishing notifications upon timeout. The next thing to do is respond to these notifications by doing something meaningful.

Responding To Timeout Notifications

A good place to respond to the timeout notifications is in your application’s delegate. This might change depending on how you are doing your logout logic, but I generally have some sort of login controller that needs to be presented modally upon timeout. Here is a snippet from the app delegate of the sample project.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
 
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidTimeout:) 
        name:kApplicationDidTimeoutNotification object:nil];
 
    return YES;
}
 
- (void) applicationDidTimeout:(NSNotification *) notif {
    LoginViewController *controller = [[[LoginViewController alloc] initWithNibName:@"LoginViewController" 
        bundle:[NSBundle mainBundle]] autorelease];
    [self.viewController presentModalViewController:controller animated:YES];
}

Notice that we add an observer for a notification named kApplicationDidTimeoutNotification. So, whenever the kApplicationDidTimeoutNotification notification fires, our app delegate will call the applicationDidTimeout: method. This method is responsible for displaying the login view controller.

Now, we have “logged the user out”. Once the user logs back in, we must reset the idle timer to ensure that they will be logged out again if they leave the device unattended.

Resetting The Timer

I have created a simple (simulated) login method inside of my login view controller that looks like this:

- (IBAction)login:(id)sender {
    [(ELCUIApplication *)[UIApplication sharedApplication] resetIdleTimer];
    [self.parentViewController dismissModalViewControllerAnimated:YES];
}

The first line of this method tells the application to reset the timer and the second reveals the interface (the user has logged back in). Obviously, this doesn’t truly simulate a user loggin in/out, but it has been simplified to demonstrate how easy our ELCUIApplication timeout functionality is.

Conclusion

As always, if you have any questions or comments feel free to leave them hear or write them to me on Twitter. Again the source for this tutorial is available on github.

Happy iCoding!

Daily iPhone App: IHeartRadio

Clear Channel is a huge force in radio. When the Telecommunications Act of 1996 opened up radio ownership, Clear Channel Communications scooped up several stations in most big markets, consolidating power.

The company also has a spinoff called Live Nation, which is among the biggest event and ticket promoters in the world (currently in a merger with Ticketmaster). In other words, Clear Channel runs the show when it comes to radio and music events.

And that’s essentially why the iHeartRadio app is so important — it’s Clear Channel’s official hook into iOS. Most of the company’s stations offer live streams within the app, along with song information and other updates. A recent update lets users create custom “stations,” similar to Pandora. Unfortunately, those features require a login through Facebook. The service itself isn’t bad, but given just how many honeypots Clear Channel has its hands in, some users aren’t exactly comfortable with passing over more private information.

That said, if the station you’re looking for is available in the app, this is essentially the only way to get it streaming on the iPhone, so this one is pretty much your choice. And there is something to be said for Clear Channel’s clout: the company is hosting a huge music festival in Las Vegas later on this month, all centered around this iHeartRadio brand. With the company’s access, the custom stations on this app have access to plenty of different music choices and songs you might not hear elsewhere.

It’s just too bad the iHeartRadio app is part of the big Clear Channel empire — something that’s crushed a lot of local radio markets (and hearts) in the past. The iHeartRadio app is now available for free in the App Store.

Daily iPhone App: IHeartRadio originally appeared on TUAW – The Unofficial Apple Weblog on Tue, 20 Sep 2011 08:00:00 EST. Please see our terms for use of feeds.

Source | Permalink | Email this | Comments

Sphero boasts new look, launch set for later this year

We saw Sphero in action in January at CES 2011, and the company has released some details on the final prototype and an actual release. The little iOS-controlled sphere is still planned for release sometime this year, but it’s got a new design that you can see above. Don’t worry, it’s still a ball, as that blue base there is just for charging and storage. The design is new, and the shell of the ball itself is different from when we saw it. It’s supposed to be a very sturdy polycarbonate material that still lets the LEDs inside shine through. Perfect for playing with cats?

There’s still no price or actual date for release yet, unfortunately, but that can’t stop you from being able to preorder one of your own if you like. Hopefully we’ll hear more about this soon. If the short time we had with it at CES was any indication, this little device should be a lot of fun when combined with your iPhone or iPad.

Sphero boasts new look, launch set for later this year originally appeared on TUAW – The Unofficial Apple Weblog on Tue, 20 Sep 2011 07:00:00 EST. Please see our terms for use of feeds.

Source | Permalink | Email this | Comments

Survey: 60 percent of back-to-school PC purchases are Macs

We’ve posted before how Apple is not only growing in terms of portable devices, but also in terms of Mac sales. Here’s another indicator of that: A survey of 158 college students, all undergrads, says 60 percent of new PC purchases by the group this year consisted of Macs. That’s not a huge sample, but it is a representative one, as more and more students are going with OS X-driven computers rather than the old desktop PC. According to the same study last year, Apple held only a 38 percent share, so interest in Macs among this group has almost doubled.

More students than last year also brought a tablet with them to school, though shares in that department are apparently leveling. Apple’s iPad is down a few percentage points, as is the Kindle, while the “other” category is up by 10 percent.

As volatile as those numbers are (which, unfortunately, casts a little bit of doubt on how relevant this study actually is), there are hints that these undergrads are definitely Mac-inclined in their back-to-school purchases. Apple may have become a mobile device company, but its Mac sales are still stronger than ever.

Survey: 60 percent of back-to-school PC purchases are Macs originally appeared on TUAW – The Unofficial Apple Weblog on Tue, 20 Sep 2011 00:00:00 EST. Please see our terms for use of feeds.

Source | Permalink | Email this | Comments

Mac 101: Format choices for USB flash drives

The overwhelming majority of USB flash drives you buy are going to come in one of two formats: FAT32 or NTFS. The first format, FAT32, is fully compatible with Mac OS X, though with some drawbacks that we’ll discuss later. If the drive comes formatted in NTFS, which is the default file system for Windows, you’re going to want to re-format the drive because Mac OS X can’t write files to NTFS-formatted volumes (at least not without a bunch of extra work that’s beyond the scope of this article).

How do you tell which format your brand-new USB drive has? Hook it up to your Mac and launch the Disk Utility app, located in your Utilities folder (which is in Applications). Your new drive should appear in the left-hand column, and clicking the “Partition” tab will bring up info on the drive which includes its current format.

If the drive’s format comes up as MS-DOS (FAT) or, less likely, ExFAT, you may be able to simply leave the drive as-is and not bother reformatting it. If the drive is listed as NTFS-formatted, you’re going to need to format it to something else if you want full compatibility with Mac OS X.

There are several possible file system formats you can use for a USB flash drive, and changing them in Disk Utility is as easy as selecting the number of partitions you want on the drive (usually just one), picking the format you want for the drive, and clicking “Apply.” Note that this will erase all information on the drive, so make absolutely sure you’ve got copies of everything before moving forward.

Disk Utility gives you five different choices for drive formats in OS X Lion. Unless you have extraordinary needs, you can safely ignore two of them: Mac OS Extended (Case-sensitive, Journaled) and Free Space. I’ll discuss the advantages and disadvantages of the other three formats below.

Mac OS Extended (Journaled) – This is the default file system format for Mac OS X drives.

Advantages: Formatting your USB flash drive this way will give you full interoperability with Macs. It also includes support for features from OS X Lion, such as Versions. You can even set up an OS X startup drive if you have the right files, the know-how, and a big enough flash drive, which will allow you to boot your Mac off an external disk if something goes wrong with your built-in drive. The “Mac OS Extended (Journaled)” option will have the highest degree of support for Mac OS X features, and there’s no limit to the size of files you can put on the drive.

Disadvantages: Windows-running PCs can read files from drives formatted this way, but they can’t write to them (at least not without the same amount of work it takes to get OS X to write to NTFS-formatted drives). If you’re transferring files from Macs to PCs, this won’t be an issue; however, transferring files from PCs to Macs won’t be possible if your drive is formatted in “Mac OS Extended (Journaled).” If you will only be working with Macs and not PCs, this may not be an issue. Otherwise, you may need to consider one of the file formats discussed below.

MS-DOS (FAT) – This is Disk Utility’s name for the FAT32 filesystem.

Advantages: FAT32 offers near-universal interoperability with virtually every computing system on the planet. A drive formatted this way can easily transfer files between Macs and PCs. You can also move files to video game systems like the PlayStation 3, Xbox 360, and Wii. Virtually all cameras and videocameras support FAT32, too. It’s the closest thing we have to a universal file system format, which is why most flash drives are formatted this way right out of the box.

Disadvantages: FAT32 doesn’t support files larger than 4 GB, and that’s its greatest drawback. You also can’t create a startup drive for your Mac using this format. Furthermore, FAT32 doesn’t support OS X Lion’s Versions feature — something users have discovered the hard way when working directly off of files stored on a USB flash drive (something we recommend against doing). However, those downsides may be more than outweighed by FAT32’s near-universal support, and if you don’t think you’re going to be dealing with files bigger than 4 GB, this may be the optimal choice.

ExFAT – A newer file format, supported in Mac OS X 10.6.5 or later.

Advantages: exFAT has many of the same advantages as FAT32 in that it’s a disk format that offers interoperability between Macs and PCs. It has one big advantage over FAT32: exFAT supports file sizes larger than 4 GB, so if you have a need to move huge files between Macs and PCs, this is likely the format you’ll want for your flash drive.

exFAT is supported by the following operating systems:

  • Mac OS X Snow Leopard (10.6.5 or greater)
  • OS X Lion
  • Windows XP SP2 or later (with an additional update for exFAT support)
  • Windows Vista SP1 or later
  • Windows 7

Disadvantages: As a relatively newer file system format, exFAT isn’t supported in older versions of Mac OS X (anything prior to 10.6.5) or anything older than Windows XP SP2. If you won’t be dealing with older Macs or PCs, this may not be a problem. Of greater issue is that most consumer electronics (cameras, camcorders, video game systems) don’t support exFAT, either. If you need to transfer files between your Mac and one of these non-PC devices, you’re almost certainly going to have to format your flash drive in FAT32 instead.

The Bottom Line

Here’s a basic rundown of which format we recommend for your USB flash drive, broken down by use case.

If you absolutely, positively will only be working with Macs and no other system, ever: Use Mac OS Extended (Journaled).

If you need to transfer files larger than 4 GB between Macs and PCs: Use exFAT.

In all other cases: Use MS-DOS (FAT), aka FAT32.

Mac 101: Format choices for USB flash drives originally appeared on TUAW – The Unofficial Apple Weblog on Mon, 19 Sep 2011 20:00:00 EST. Please see our terms for use of feeds.

Source | Permalink | Email this | Comments

Appcelerator launches app store for app components

Stick with us on this one — Appcelerator has just launched an App Store, but not for apps. Instead, it’s for components for apps, offering designs, templates, extensions, and other tools to app developers, who can then use those to make mobile apps for various other app stores, including Apple’s own iOS marketplace. These components allow devs (for a cost or for free) to put together apps with various kinds of features together quickly and relatively easily, either leaving more time for iteration and design, or simply allowing releases to happen faster.

Most of the components on the store make use of Appcelerator’s Titanium platform, which is a cross-OS setup for developing both web and native mobile apps, so any developers interested in using these components will probably need to check that out first. But once you’ve got that down, Appcelerator’s new market is a sort of a meta-marketplace, offering pre-made services and components to devs who have more money than time to spend on development.

Essentially, this is just another indicator of how popular and gigantic the mobile app market is — there are marketplaces for even the components that make up the apps that are selling so well.

Appcelerator launches app store for app components originally appeared on TUAW – The Unofficial Apple Weblog on Mon, 19 Sep 2011 19:00:00 EST. Please see our terms for use of feeds.

Source | Permalink | Email this | Comments

Apple issues Thunderbolt Display firmware update

Apple has released a Thunderbolt Display firmware update for the new displays they started shipping just last week. The Thunderbolt Display Firmware Update 1.0 improves the stability of the Apple Thunderbolt Display. The update weighs in at just 923 KB and requires Mac OS X 10.6.8 or OS X Lion 10.7.1 or later.

Apple issues Thunderbolt Display firmware update originally appeared on TUAW – The Unofficial Apple Weblog on Mon, 19 Sep 2011 18:36:00 EST. Please see our terms for use of feeds.

Source | Permalink | Email this | Comments

Monkey Island series on sale, Temple Run free for TLAP day

Yaarrrr maties! It be Talk Like a Pirate day here on these Internets, and folks from all over be talkin’ like they were Davy Jones himself. But even if ye landlubbers can’t abide the bad Blackbeard impressions, fear not — Telltale Games be pouring ale in your mug, by puttin’ all the iPad Monkey Island Tales series on sale for half price. Yes indeed, me lads: For today only, ye can pick up all six episodes of the series for only $2.99. That’s the same as three gold doubloons, if all yer fortune happens to come from finding the treasure of an ancient Spanish freighter off the Black Isles of the Carribbean!

And that’s not all, ye scurvy swamprats! Imangi Studios’ Temple Run is free for today, in order to celebrate a new update for the app that adds more characters, powerups, and achievements to earn. It’s a solid update for a solid game, so if ye scallywags haven’t gone on the run just yet, now’s the time to do it. So there’s two solid deals on this Talk Like a Pirate holiday for ye — make sure to take advantage of ’em, or you’ll be walkin’ the plank before sunset!

Monkey Island series on sale, Temple Run free for TLAP day originally appeared on TUAW – The Unofficial Apple Weblog on Mon, 19 Sep 2011 18:00:00 EST. Please see our terms for use of feeds.

Source | Permalink | Email this | Comments

Chrome hits version 14, adds Lion features

Google has issued a new stable, public release of its popular Chrome web browser. For developers, Chrome version 14 adds the new Web Audio API, which allows developers to add cool audio effects like room simulation and spatialization. However, the best things about Chrome 14 are the enhancements for OS X Lion users.

Chrome 14 finally adds native Lion full-screen mode support. The browser also features a number of Lion “visual polishes” as well as support for Lion’s overlay scroll bars. Google Chrome version 14 is a free download.

Chrome hits version 14, adds Lion features originally appeared on TUAW – The Unofficial Apple Weblog on Mon, 19 Sep 2011 17:30:00 EST. Please see our terms for use of feeds.

Source | Permalink | Email this | Comments

LVL Patent Group sues Apple and others over cell phone technology patents

Apple is the target of yet another patent lawsuit, this time filed by a company named LVL Patent Group, who claims that Apple and other cellphone companies are violating up to four generic patents they have the rights to. The patents revolve around transferring data and using various devices for entering transactions, and though most of the patents were reportedly filed back before the year 2000, there is one that was only approved this past week.

In other words, LVL is trolling for patent damages. Apple is far from the only company included in the lawsuits: HP, HTC, Motorola, Nokia, RIM, and Samsung are all listed as well, with a host of other cell phone and related companies. It’s a pretty standard maneuver: try to cause just enough trouble to make it easier for these companies to simply pay off the complaint rather than bother fighting it in court. We’ll see how it works its way through the courts.

LVL Patent Group sues Apple and others over cell phone technology patents originally appeared on TUAW – The Unofficial Apple Weblog on Mon, 19 Sep 2011 17:00:00 EST. Please see our terms for use of feeds.

Source | Permalink | Email this | Comments

Samsung already planning legal action against iPhone 5

Samsung has announced that it will launch legal action against Apple the very instant the iPhone 5 steps foot in Korea, according to Korea Times. Specifically, the manufacturer will move to block sales of Apple’s phone.

Quoting an unnamed source identified only as an anonymous Samsung senior executive, Korea Times notes that Samsung will “…take Apple to court here for its violation of Samsung’s wireless technology related patents.” Additionally, the Samsung source reiterated his/her company’s dedication to its battle with Apple, saying, “For as long as Apple does not drop mobile telecommunications functions, it would be impossible for it to sell its i-branded products without using our patents. We will stick to a strong stance against Apple during the lingering legal fights.”

This is the latest volley in the legal back-and-forth between these two tech giants. As of this writing, it looks like the battle has only begun.

[Via AppleInsider]

Samsung already planning legal action against iPhone 5 originally appeared on TUAW – The Unofficial Apple Weblog on Mon, 19 Sep 2011 16:30:00 EST. Please see our terms for use of feeds.

Source | Permalink | Email this | Comments

OWC unleashes Mercury Aura Pro Express 6G SSD for MacBook Air

Other World Computing has released the Mercury Aura Pro Express 6G SSD upgrade kit for 2011 MacBook Airs. The SSD releases some serious speed in the latest MacBook Air models thanks to their SATA Revision 3.0, 6Gb/s buses.

The Mercury Aura Pro Express 6G will give the 2011 Airs over 500MB/s read & 450MB/s write speeds. OWC says real world use will be up to 68% faster than stock MacBook Airs from Apple and that critical 4K random reads/writes will be up to 3.5X faster. Pretty impressive.

The upgrades don’t come cheap, however. A 120 GB Aura Pro Express 6G costs US$349 and the 240 GB model costs $599. OWC also offers Mercury Aura Pro Express 3G SSD upgrades for both the 2010 and 2011 MacBook Airs. The 3G variety runs at over 275MB/s data rates and cost $319/449/1227 for the 18/240/480 GB models.

[via Engadget]

OWC unleashes Mercury Aura Pro Express 6G SSD for MacBook Air originally appeared on TUAW – The Unofficial Apple Weblog on Mon, 19 Sep 2011 16:00:00 EST. Please see our terms for use of feeds.

Source | Permalink | Email this | Comments

Daily Update for Sept. 19, 2011

It’s the TUAW Daily Update, your source for Apple news in a convenient audio format. You’ll get all the top Apple stories of the day in three to five minutes, which is perfect for a quick review of what’s happening in the Apple world.

You can listen to today’s Apple stories by clicking the inline player (requires Flash) or the non-Flash link below. To subscribe to the podcast for listening through iTunes, click here.

No Flash? Click here to listen.

Daily Update for Sept. 19, 2011 originally appeared on TUAW – The Unofficial Apple Weblog on Mon, 19 Sep 2011 15:30:00 EST. Please see our terms for use of feeds.

Source | Permalink | Email this | Comments

Daily Mac App: inPaint

I’ve used Photoshop for years, and recently upgraded to Photoshop CS5 mainly for one feature called Content-Aware Fill. It allows you to remove an element from an image, and the software very cleverly fills it in based on what is around the deleted object. It’s quite amazing to use, and I’m often calling it up for landscape photos when an errant tourist or power line gets in the way of what would otherwise be a nice image.

If you’re not about to shell out several hundred for Photoshop, or almost a hundred for Photoshop Elements which has a similar feature, let me direct your attention to inPaint in the Mac app store. This US $9.95 app (on sale for about a week for $5.00) has this same feature, and if removal of some parts of an image is what you really want it’s worth the small price asked.

Here’s how it works: You open an image in inPaint. You use a brush tool to paint out the object you want removed, then you hit a ‘play’ button to start the repair. The brush tool can be varied in size, and you can brush away multiple unconnected objects in one operation.

I tried inPaint on a variety of images, and compared how it did to Photoshop CS5 content-aware fill. In some cases, inPaint removed the object with fewer steps and left no evidence it had been used, where Photoshop left the image looking a big ragged. In other cases, the two applications worked about the same, but in none of my experiments did Photoshop do a superior job.

inPaint is not a substitute for a high-end editor. No layers, no sharpening, nothing really except the ability to smoothly remove parts of an image without a trace.

One drawback is the app can’t open raw files. The developer says that is coming. I had no trouble opening TIF, JPEG or PNG format images.

Photoshop is a terrific app. I use it every day. It is versatile, and does everything a graphic artist or photographer would want. However, if you are looking only for the ability to smoothly remove unwanted things in your image, inPaint does it extraordinarily well at an almost microscopic price. I have some examples of the app and a Photoshop CS5 comparison in the gallery.

Gallery: inPaint for Mac

2 people in Death ValleyWith inPaint you brush over themAfter a few seconds the people are smoothly removedUsing Photoshop CS5 to do the same operationPerson at Grand Canyon

Daily Mac App: inPaint originally appeared on TUAW – The Unofficial Apple Weblog on Mon, 19 Sep 2011 15:00:00 EST. Please see our terms for use of feeds.

Source | Permalink | Email this | Comments

iCloud reset set for September 22

Yesterday afternoon, Apple announced to developers that it will be resetting all iCloud backup data on Thursday, September 22nd. The following message was posted on the Apple Developer boards:

On Thursday, September 22, the iCloud Backup data will be reset. Backing up to iCloud or restoring from an iCloud backup will be unavailable from 9 AM PDT – 5 PM PDT. If you attempt a backup or restore during this time, you will receive an alert that the backup or restore was not successful. After this reset, you will be unable to restore from any backup created prior to September 22. A full backup will happen automatically the next time your device backs up to iCloud.

Apple had originally warned developers that anything saved to iCloud servers might be wiped clean before the final release of iOS 5. Yesterday’s announcement from Apple is another sign that development on iOS 5 and iCloud is quickly wrapping up. Indeed, some rumors have even suggested that developers will see a release of the gold master of iOS 5 this Friday, September 23, with Apple unveiling the iPhone and iOS 5 on September 30, and launching the next iPhone on October 7.

[via 9to5Mac]

iCloud reset set for September 22 originally appeared on TUAW – The Unofficial Apple Weblog on Mon, 19 Sep 2011 14:30:00 EST. Please see our terms for use of feeds.

Source | Permalink | Email this | Comments