Tag Archives: iOS 8

How to check if the Alex Voice is installed in iOS

Talk-Icon-512Alex is Apple’s high-quality voice that users can download and use with VoiceOver and any text-to-speech application, including the native AVSpeechSynthesizer methods.

However, Alex is an optional file that users can download if they wish, and he’s rather large too (about 900MB). Hence we can’t rely on this voice being available.

While your iOS app can request to play an utterance using Alex, iOS will default to the low-quality standard voice if Alex is not available. So how can we check if he’s around?

Here’s a quick method that lets us do just that: it checks if the Alex voice as been downloaded to the device, and lets you react accordingly – perhaps by letting the user know that an enhancement is available and how to get it:

- (void)checkForAlex {
    
    // is Alex installed?
    BOOL alexInstalled = NO;
    NSArray *voices = [AVSpeechSynthesisVoice speechVoices];
    
    for (id voiceName in voices) {
        
        if ([[voiceName valueForKey:@"name"] isEqualToString:@"Alex"]) {
            alexInstalled = YES;
        }
    }
    
    // react accordingly
    if (alexInstalled) {
        NSLog(@"Alex is installed on this device.");
    } else {
        NSLog(@"Alex is not installed on this device.");
    }
}

This method loops through all installed voices and queries each voice’s name. If Alex is among them, he’s installed. You can also query other names (each voice has a name identifier), and if an “enhanced” version is available using the “quality” parameter ( 1 = standard, 2 = enhanced).

Query the “language” parameter to see which languages are available for speech on the current device (returns a language code like en-US).

For testing: here’s a quick method that writes all available voice names and parameters out as log messages:

- (void)showAllVoices {
    
    // display a list of all available voices
    NSArray *voices = [AVSpeechSynthesisVoice speechVoices];
    for (id voiceName in voices) {

        NSLog(@"Language Code: %@", [voiceName valueForKey:@"language"]);
        NSLog(@"Name: %@", [voiceName valueForKey:@"name"]);
        NSLog(@"Quality: %@", [voiceName valueForKey:@"quality"]);
        NSLog(@"Identifier: %@", [voiceName valueForKey:@"identifier"]);
        NSLog(@"-----------------------");
    }
}




How to access the barometer in iOS 8

image

The iPhone 6 introduced a new piece of hardware: a barometer with which we can detect air pressure and the device’s relative altitude. With it, iOS 8 gave us a couple of classes to access this data as part of the Core Motion framework.

Let’s see how we can access those barometer values.

Continue reading





How to link directly to your app’s Settings section

Screen Shot 2015-09-24 at 09.37.14

iOS 8 introduced a new UIApplication method that lets us deeply link to our own app’s section in the iOS Settings app. Previously users had to open the Settings app and hunt for the relevant section, which isn’t always easy to find.

To make use of this handy function, add a Settings.bundle to your app (if you don’t already have one), then open the Settings app with the following method:

[[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];

It looks a bit complicated because we’re using three methods in one. We could also write those out to make it a bit easier to understand:

NSString *settings = UIApplicationOpenSettingsURLString;
NSURL *settingsURL = [NSURL URLWithString:settings];
[[UIApplication sharedApplication]openURL:settingsURL];

In essence we call openURL on UIApplication, with a URL which is defined in an enum constant (UIApplicationOpenSettingsURLString). The latter needs to be converted into a URL via the NSURL method URLwithString. Call this method and iOS will transition to the correct section in the Settings app.

Xcode / Simulator Bug

Note that there is a bug in Xcode that makes the Settings section sometimes show up empty. You can trigger this bug if you deploy from Xcode to Simulator or a real device and then execute this code. You must reboot Simulator or your device for the correctly populated Settings section to show up again.

To prevent any panic attacks from happening, deploy the app from Xcode and stop it. Head back to the app and trigger your method to execute the code. Only then will the section show up as it should. In a real world scenario this isn’t an issue because users won’t ever start your app directly from Xcode.





How to use Touch ID in iOS 8

Screen Shot 2015-09-23 at 15.58.11

Since iOS 8 we can use the Touch ID sensors in compatible devices and authenticate sensitive data in our own apps. Here’s how to do it, short and simple.

Framework

First we’ll need to add the Local Authentication Framework to our app. To do that, navigate to your target and find the Linked Framework and Libraries section at the bottom. Click that little plus icon and search for “local”.

Screen Shot 2015-09-23 at 11.27.02

Code

Now that the framework is linked, we’ll need to import it into the class that does the verifying. I’ll use a simple view controller from the Single View application template here.

@import LocalAuthentication;

Nice. Now I’ll hook up an action to which the authentication can be triggered. Here’s what it looks like when we’re done:

- (IBAction)authenticateTouchID {
    
    // create a context and error object
    LAContext *context = [[LAContext alloc]init];
    NSError *error = nil;
    NSString *reason = @"We want to authenticate your fingerprints";
    
    // check if the device supports Touch ID
    if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
        
        NSLog(@"Device supports Touch ID");
        
        // authenticate the user
        [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:reason reply:^(BOOL success, NSError * _Nullable error) {
            
            // it worked!
            if (success) {
                NSLog(@"Successfully authenticated the user via Touch ID. HUZZAH!");
            } else {
                NSLog(@"Could not authenticate the user via Touch ID. \nReason: %@ \nError Code: %ld", error.localizedDescription, error.code);
                
                // if the user chooses the password option
                if (error.code == -3) {
                    // handle password input here
                    NSLog(@"Let's ask for your password instead");
                }
            }
        }];
        
    } else {
        // Touch ID is not available
        NSLog(@"Touch ID is not available.");
    }
}

It looks a little scary, so let’s sift through this one step at a time. At the beginning we’ll create a Local Authentication Context. It’s just a class with one particular method we can call. We’ll also create an error object and a string that will appear as the message when the Touch ID view is brought up. The error allows us to check why Touch ID was not available at the end of our message if we so desire.

    // create a context and error object
    LAContext *context = [[LAContext alloc]init];
    NSError *error = nil;
    NSString *reason = @"We want to authenticate your fingerprints";

Next up we’ll check if Touch ID is actually available. We’ll do that my calling evaluatePolicy: on our context. If this is successful, the Touch ID check can go ahead. If not, we can either ignore it or implement something like a password check instead (I’ve only implemented a log message here).

If the check is successful we can do the actual authentication, using the same method. The parameter for checking is an enumeration with the awesome name LAPolicyDeviceOwnerAuthenticationWithBiometrics (biometrics being the fingerprint part of the context – perhaps when Apple release devices with retina scanners, face detection or DNA verification we’ll have other values here).

// authenticate the user
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:reason reply:^(BOOL success, NSError * _Nullable error) {
            
    // it worked!
    if (success) {
    NSLog(@"Successfully authenticated the user via Touch ID. HUZZAH!");
    } else {
    NSLog(@"Could not authenticate the user via Touch ID. \nReason: %@ \nError Code: %ld", error.localizedDescription, error.code);
                
    // if the user chooses the password option
    if (error.code == -3) {
        // handle password input here
        NSLog(@"Let's ask for your password instead");
        }
    }
}];

Note that there is one other value in this enumeration called LAPolicyDeviceOwnerAuthentication. Don’t use that: although it’s available, and it brings up the lock screen’s familiar passcode entry view, it’s throwing an exception when I tried to use it. I’ve not found anything in the Apple documentation on this value, although Xcode does suggest it as part of code completion. Anyway, moving on…

It’s a long method that takes a completion block (reply), inside which we handle the authentication. If the Touch ID is not successful, iOS automatically brings up an additional option that asks for a password.

Screen Shot 2015-09-23 at 15.58.32

To handle a user pressing that option, we’ll check for the error.code property: if it’s -3, it means that the user has selected the Fallback Mechanism. We’ll handle it here. Handle other error codes here too if you like and let the user know what’s going on and why.

And that’s it! Everything else is handled by iOS.

Testing

You can test this code on Touch ID devices (iPhone 5s, iPad Air 2, etc) as well as on the simulator. By default Touch ID will be disabled. Enable it by heading over to Hardware – Touch ID Enrolled.

To trigger a correct or failed finger touch use the appropriate option under

Hardware – Simulate Finger Touch

.

Screen Shot 2015-09-23 at 16.28.04

Demo Project and Documentation

Here’s a demo project on GitHub that shows this code in action:

Here’s Apple’s official documentation about Touch ID:





What’s new in iOS 8.3 and Xcode 6.3

iOS 8.3 includes improved performance, bug fixes, and a redesigned Emoji keyboard. Changes include:

Improved performance for:

  • App launch
  • App responsiveness
  • Messages
  • Wi-Fi
  • Control Center
  • Safari tabs
  • 3rd-party keyboards
  • Keyboard shortcuts
  • Simplified Chinese keyboard

Wi-Fi and Bluetooth fixes

  • Fixes an issue where you could be continuously prompted for login credentials
  • Addresses an issue where some devices disconnect intermittently from Wi-Fi networks
  • Fixes an issue where hands-free phone calls could become disconnected
  • Fixes an issue where audio playback could stop working with some bluetooth speakers

Orientation and rotation fixes

  • Addresses an issue that sometimes prevented rotating back to portrait after having rotated to landscape
  • Improves performance and stability issues that occurred when rotating the device between portrait and landscape
  • Fixes an issue where device orientation appeared upside down after pulling the iPhone 6 Plus from your pocket
  • Resolves an issue that sometimes prevented apps from rotating to correct orientation after switching apps in multitasking

Messages fixes

  • Addresses issues that caused group messages to sometimes split
  • Fixes an issue that sometimes removed the ability to forward or delete individual messages
  • Resolves an issue that sometimes prevented a preview from appearing when taking a photo in Messages
  • Adds the ability to report junk messages directly from the Messages app
  • Adds the ability to filter out iMessages that are not sent by your contacts

Family Sharing fixes

  • Fixes a bug where certain apps would not launch or update on family members’ devices
  • Fixes a bug that prevented family members from downloading certain free apps
  • Increased reliability for Ask to Buy notifications

CarPlay fixes

  • Fixes an issue where Maps could come up as a black screen
  • Fixes an issue where the UI could be incorrectly rotated
  • Fixes an issue where the keyboard could appear on the CarPlay screen when it shouldn’t

Enterprise fixes

  • Improves reliability of installing and updating enterprise apps
  • Corrects the time zone of Calendar events created in IBM Notes
  • Fixes a problem that could cause web clip icons to become generic after restarting
  • Improves reliability of saving the password for a web proxy
  • Exchange out-of-office message can now be edited separately for external replies
  • Improves recovery of Exchange accounts from temporary connection problems
  • Improves compatibility of VPN (espeacially VPN australia) and web proxy solutions
  • Allows use of physical keyboards to log into Safari web sheets, such as for joining a public Wi-Fi network
  • Fixes an issue that caused Exchange meetings with long notes to be truncated

Accessibility fixes

  • Fixes an issue where using the back button in Safari causes VoiceOver gestures to not respond
  • Fixes an issue where VoiceOver focus becomes unreliable in draft Mail messages
  • Fixes an issue where Braille Screen Input cannot be used to type text in forms on webpages
  • Fixes an issue where toggling Quick Nav on a Braille Display announces that Quick Nav is off
  • Fixes an issue keeping app icons from being moveable on home screen when VoiceOver is enabled
  • Fixes an issue in Speak Screen where speech will not start again after pausing

Other improvements and bug fixes

  • Introduces a redesigned Emoji keyboard with over 300 new characters
  • iCloud Photo Library has been optimized to work with the new Photos app on OS X 10.10.3 and is now out of beta
  • Improves the pronunciation of street names during turn-by-turn navigation in Maps
  • Includes support for Baum VarioUltra 20 and VarioUltra 40 braille displays
  • Improves the display of Spotlight results when Reduce Transparency is turned on
  • Adds Italic and Underline format options for iPhone 6 Plus landscape keyboard
  • Adds the ability to remove shipping and billing addresses used with Apple Pay
  • Additional language and country support for Siri: English (India, New Zealand), Danish (Denmark), Dutch (Netherlands), Portuguese (Brazil), Russian (Russia), Swedish (Sweden), Thai (Thailand), Turkish (Turkey)
  • Additional dictation languages: Arabic (Saudi Arabia, United Arab Emirates) and Hebrew (Israel)
  • Improves stability for Phone, Mail, Bluetooth connectivity, Photos, Safari tabs, Settings, Weather and Genius Playlists in Music
  • Addresses an issue where Slide to Unlock could fail to work on certain devices
  • Addresses an issue that sometimes prevented swiping to answer a phone call on the Lock screen
  • Addresses an issue that prevented opening links in Safari PDFs
  • Fixes an issue where selecting Clear History and Website Data in Safari Settings did not clear all data
  • Fixes an issue that prevented autocorrecting “FYI”
  • Addresses an issue where contextual predictions did not appear in Quick Reply
  • Fixes an issue where Maps did not enter night mode from hybrid mode
  • Resolves an issue that prevented initiating FaceTime calls from a browser or 3rd-party app using FaceTime URLs
  • Fixes an issue that sometimes prevented photos from properly exporting to Digital Camera Image folders on Windows
  • Fixes an issue that sometimes prevented an iPad backup from completing with iTunes
  • Fixes an issue that could cause Podcast downloads to stall when switching from Wi-Fi to cellular networks
  • Fixes an issue where remaining time on timer would sometimes incorrectly display as 00:00 on Lock screen

What’s new in Xcode 6.3

Screen Shot 2015-04-11 at 12.25.30

Apple have the following document available which explains the changes in Xcode better than the above screenshot: https://developer.apple.com/library/ios/documentation/DeveloperTools/Conceptual/WhatsNewXcode/Articles/Introduction.html#//apple_ref/doc/uid/TP40004635-SW1

Further Reading





What's new in iOS 8.2

Screen Shot 2015-03-12 at 10.44.02This release introduces support for Apple Watch, and also includes improvements to the Health app, increased stability and bug fixes.

Apple Watch support

  • New Apple Watch app to pair and sync with iPhone, and to customize watch settings
  • New Activity app for viewing fitness data and achievements from Apple Watch; appears when Apple Watch is paired
  • Available on iPhone 5 and later

Health app improvements

  • Adds the ability to select the unit of measurement for distance, body temperature, height, weight and blood glucose
  • Improves stability when dealing with large amounts of data
  • Includes the ability to add and visualize workout sessions from 3rd-party apps
  • Addresses an issue that may have prevented users from adding a photo in Medical ID
  • Fixes units for vitamins and minerals
  • Fixes an issue where Health data wouldn’t refresh after changing data source order
  • Fixes an issue where some graphs showed no data values
  • Adds a privacy setting that enables turning off tracking of steps, distance and flights climbed

Stability enhancements

  • Increases stability of Mail
  • Improves stability of Flyover in Maps
  • Improves stability of Music
  • Improves VoiceOver reliability
  • Improves connectivity with Made for iPhone Hearing Aids

Bug fixes

  • Fixes an issue in Maps that prevented navigating to some favorite locations
  • Addresses an issue where the last word in a quick reply message wasn’t autocorrected
  • Fixes an issue where duplicate iTunes purchased content could prevent iCloud restore from completing
  • Resolves an issue where some music or playlists didn’t sync from iTunes to the Music app
  • Fixes an issue where deleted audiobooks sometimes remained on device
  • Resolves an issue that could prevent call audio from routing to car speakers while using Siri Eyes Free
  • Fixes a Bluetooth calling issue where no audio is heard until the call is answered
  • Fixes a timezone issue where Calendar events appear in GMT
  • Addresses an issue that caused certain events in a custom recurring meeting to drop from an Exchange calendar
  • Fixes a certificate error that prevented configuring an Exchange account behind a third-party gateway
  • Fixes an issue that could cause an organizer’s Exchange meeting notes to be overwritten
  • Resolves an issue that prevented some Calendar events from automatically showing as ‘Busy’ after accepting an invite

For information on the security content of this update, please visit this website:

http://support.apple.com/kb/HT1222