Easily Overlooked New Features in iOS 7

Check out this list of easily overlooked features in iOS 7 – there will probably be a few you’ve never heard of! By .

Leave a rating/review
Save for later
Share
You are currently viewing page 2 of 4 of this article. Click here to view the first page.

4. iOS now requests user consent for apps to use the microphone

In previous versions, iOS prompted the user for permission to retrieve the user’s location to access their contacts, calendars, reminders and photos, to receive push notifications and to use their social networks. In iOS 7, access to the microphone is now on that list. If the user doesn’t grant permission for an app to use the microphone, then apps using the microphone will only receive silence.

Here’s a bit of code you can use to detect if your app has been given permission to access the microphone:

// The first time you call this method, the system prompts the user to grant your app access
// to the microphone; any other time you call this method, the system will not prompt the user
// and instead passes the previous value for 'granted'
[[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted) {
    if (granted) {
        // the user granted permission!
    } else {
        // maybe show a reminder to let the user know that the app has no permission?
    }
}];

Also note that using any methods to access the microphone before the user has granted permission will cause iOS to display the following alert:

Apps on iOS 7 needs to get your permission to access the microphone!

Apps on iOS 7 needs to get your permission to access the microphone!

The Good News: Enhancements & Deprecations

So that’s it for the significant stuff that can break your existing apps. However, there’s a few enhancements and deprecations of existing APIs that may affect your apps in other ways that you might not notice at first glance.

5. Implementation of -[NSArray firstObject]

-[NSArray firstObject] is probably one of the most requested APIs in Objective-C. A simple search on Open Radar shows several requests that have been filed with Apple. The good news is that it’s finally available. firstObject actually goes back as far as iOS 4.0, but only as a private method. Previously, developers worked around this in the following fashion:

NSArray *arr = @[];
id item = [arr firstObject];
// previously you had to do the following:
id item = [arr count] > 0 ? arr[0] : nil;

Since the above pattern was fairly common, several people added this as a category to NSArray and created their own firstObject method. Do a quick search on GitHub and you’ll see just how many times this has been implemented in the past.

The problem with this approach is that method names in categories should be unique, otherwise the behavior of this method can be unexpected. Apple recommends that you always prefix method names when creating categories on Framework classes. Be sure to check if you have any custom code that implements firstObject on NSArray and either preface it as necessary, or remove it entirely.

6. Introduction of instancetype

instancetype has the effect of making iOS 7 APIs diffs a lot harder to read. Apple changed most initializers and convenience constructors to return instancetype instead of id. But what is this new keyword, anyway?

instancetype is used in method declarations to indicate the return type to the compiler; it indicates that the object returned will be an instance of the class on which the method is called. It’s better than returning id as the compiler can do a bit of error-checking against return types at compile time, as opposed to only detecting these issues at run time. It also does away with the need to cast the type of the returned value when calling methods on subclasses.

The long and short of instancetype? Basically, use it whenever possible.

You can read more about instancetype in What’s New in Objective-C and Foundation in iOS 7 by Matt Galloway, as well as on NSHipster.

7. Tint images with UIImage.renderingMode

Tinting is a big part of the new look and feel of iOS 7, and you have control whether your image is tinted or not when rendered. UIImage now has a read-only property named renderingMode as well as a new method imageWithRenderingMode: which uses the new enum UIImageRenderingMode containing the following possible values:

UIImageRenderingModeAutomatic      // Use the default rendering mode for the context where the image is used
UIImageRenderingModeAlwaysOriginal // Always draw the original image, without treating it as a template
UIImageRenderingModeAlwaysTemplate // Always draw the image as a template image, ignoring its color information

The default value of renderingMode is UIImageRenderingModeAutomatic. Whether the image will be tinted or not depends on where it’s being displayed as shown by the examples below:

UIImageRenderingMode Cheat Sheet

UIImageRenderingMode Cheat Sheet

The code below shows how easy it is to create an image with a given rendering mode:

UIImage *img = [UIImage imageNamed:@"myimage"];
img = [img imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];

8. Usage of tintColor vs barTintColor

In iOS 7 you can tint your entire app with a given color or even implement color themes to help your app stand out from the rest. Setting the tint color of your app is as easy as using the new property tintColor of UIView.

Does that property sound familiar? it should — some classes such as UINavigationBar, UISearchBar, UITabBar and UIToolbar already had a property with this name. They now have a new property: barTintColor.

In order to avoid getting tripped up by the new property, you should perform the following check if your app needs to support iOS 6 or earlier:

UINavigationBar *bar = self.navigationController.navigationBar;
UIColor *color = [UIColor greenColor];
if ([bar respondsToSelector:@selector(setBarTintColor:)]) { // iOS 7+
    bar.barTintColor = color;
} else { // what year is this? 2012?
    bar.tintColor = color;
}

9. Texture colors are gone

More victims of Jony Ive

More victims of Jony Ive

Texture colors? Yup, they’re gone. You can’t create colors that represent textures anymore. According to the comments in UIInterface.h, -[UIColor groupTableViewBackgroundColor] was supposed to be deprecated in iOS 6, but instead, it just doesn’t return the textured color it used to. However, the following colors have been deprecated in iOS 7:

+ (UIColor *)viewFlipsideBackgroundColor;
+ (UIColor *)scrollViewTexturedBackgroundColor;
+ (UIColor *)underPageBackgroundColor;

10. UIButtonTypeRoundRect has been deprecated in favor of UIButtonTypeSystem

Good bye, old friend.

Good bye, old friend.

One of your old friends from your beginnings in iOS development (and a popular control in many rapid prototypes) is now defunct: UIButtonTypeRoundRect has been replaced by a new UIButtonTypeSystem. Excuse the dust, but progress we must! :]