Posted by: bearc0025 | February 7, 2012

How to Make an App: iPhone Lock Screen Image

If your app plays music, you may want to handle the remove audio control events. And you might also want to display applicable info like album art and the track name.

It’s not complicated, you mainly just need to know when to update it and what’s available to update. I use a method called updateNowPlaying.

  1. First make sure you’re dealing w/ iOS 5.
  2. Then create your image and trackname.
  3. Use those two items in an array and a matching array of key values (here’s a list of all the key options).
  4. Create a dictionary of the objects and keys.
  5. Set the now playing info (the dictionary from above) in the now playing info center.

 

-(void)updateNowPlaying;
{
    /* make sure the have iOS 5 by checking for the applicable class. */
    // Step 1: Check for iOS 5
    if ([MPNowPlayingInfoCenter class])  
    {
        // Step 2: image and track name
        UIImage *musicImage = [UIImage imageNamed:@"logo.png"];
        MPMediaItemArtwork *albumArt = [[MPMediaItemArtwork alloc] 
            initWithImage:musicImage];

        NSString *trackName = [musicFiles objectAtIndex:curAudioFileIndex];

        // Step 3: Create arrays
        NSArray *objs = [NSArray arrayWithObjects:
            trackName,
            albumArt, nil];

        NSArray *keys = [NSArray arrayWithObjects:
            MPMediaItemPropertyTitle,
            MPMediaItemPropertyArtwork, nil];

        // Step 4: Create dictionary.
        NSDictionary *currentTrackInfo = [NSDictionary dictionaryWithObjects:objs forKeys:keys];

        // Step 5: Set now playing info
        [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = currentTrackInfo;
    }
}


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Categories

Follow

Get every new post delivered to your Inbox.

Join 169 other followers