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 .
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Contents
Easily Overlooked New Features in iOS 7
30 mins
- The Bad News, the Good News, and the Really Good News
- The Bad News: App-Breaking Changes
- 1. -[UIDevice uniqueIdentifier] is no more
- 2. UIPasteboard as shared area is now sandboxed
- 3. MAC addresses can’t be used to identify a device
- 4. iOS now requests user consent for apps to use the microphone
- The Good News: Enhancements & Deprecations
- 5. Implementation of -[NSArray firstObject]
- 6. Introduction of instancetype
- 7. Tint images with UIImage.renderingMode
- 8. Usage of tintColor vs barTintColor
- 9. Texture colors are gone
- 10. UIButtonTypeRoundRect has been deprecated in favor of UIButtonTypeSystem
- The Really Good News: New Features
- 11. Check which wireless routes are available
- 12. Get information about the cellular radio signal
- 13. Sync passwords between user’s devices via iCloud
- 14. Display HTML with NSAttributedString
- 15. Use native Base64
- 16. Check screenshots with UIApplicationUserDidTakeScreenshotNotification
- 17. Implement multi-language speech synthesis
- 18. Use the new UIScreenEdgePanGestureRecognizer
- 19. Realize Message.app behavior with UIScrollViewKeyboardDismissMode
- 20. Detect blinks and smiles with CoreImage
- 21. Add links to UITextViews
- Where to Go From Here?
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:
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:
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
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;