All posts by Jay Versluis

About Jay Versluis

Jay is the founder of Pinkstone Pictures and WP Hosting. He has been developing iOS Apps since 2011, several of which have made it to the App Store. In his spare time he likes to develop WordPress plugins and drawing on tablet devices. He blogs about his coding journey here and at http://wpguru.co.uk.

How to turn an ISO language code into the language identifier

Oftentimes we deal with cryptic language abbreviations, such as en-GB or de-DE. While it’s more or less clear to us humans what this means, it would be nice to have a way to display something more readable to our users.

We can do this with a method from the NSLocale object. Consider this snippet:

NSString *code = @"en-GB";
NSLocale *locale = [NSLocale currentLocale];
NSString *translation = [locale displayNameForKey:NSLocaleIdentifier value:code];

NSLog(@"%@ is %@", code, translation);

// output:
en-GB is English (United Kingdom)

Here we translate en-GB into “English (United Kingdom)”. First we take the current device’s locale, then we use the displayNameForKey method to turn the ISO language code into a human readable description.

The beauty is that no matter what language the device is set to, iOS will display the translation in the matching locale. For example, on a German device, en-GB would be translated into “English (Vereinigtes Königreich)”. Even though Germans would probably never refer to the UK as that. But I digress.

This also works with abbreviated language codes, such as “en” (instead of en-GB). In that case, the output is simply “English” without the country identifier.

We can also force iOS to display the translation in a locale of our choice. Rather than using the currently selected locale on the device, we can pick one and display the output accordingly:

NSString *code = @"en-GB";
NSLocale *locale = [NSLocale localeWithLocaleIdentifier:@"fr-FR"];
NSString *translation = [locale displayNameForKey:NSLocaleIdentifier value:code];

NSLog(@"%@ is %@", code, translation);

// output:
en-GB is anglais (Royaume-Uni)




How to explode an NSString into single NSString characters

Say you had an NSString, and you’re interested in each single character. You’d think there’s a method for it, such as getCharactersInRange. Turns out that’s not really helpful, because it delivers unichar characters rather than NSStrings.

To extract single characters as NSStrings, we can use the substringWithRange method like so:

NSString *phrase = @"Complex stuff.";

// split NSString into its characters
for (int i=0; i<phrase.length; i++) {
    NSRange range = NSMakeRange(i, 1);
    NSString *character = [phrase substringWithRange:range];
    NSLog(@"Character is %@", character);
}

 





What’s New in iOS 10

iOS 10From the upgrade dialogue:

iOS 10 is the biggest release of iOS ever.

A massive update to Messages brings the power of the App Store to your conversations and makes messaging more personal than ever.

Find your route with beautifully redesigned Maps. Relive memories like never before in Photos. Use the power of Siri in more apps than ever. A new Home app to make controlling your home even easier. And all-new Music and News.iOS 10 introduces new features and improvements including:

Messages lets you express yourself in new ways and access your favorite apps right in your conversations

Siri now works with apps from the App Store to send messages, make phone calls, and more

Maps comes with an all new look and extensions to make reservations and book a ride

Photos is all-new with intelligent search making it easier to find people, places and more as well as new and beautiful ways to rediscover your memories

Home is a new app that lets you simply and securely manage your home automation products in one place

Apple Music has an all-new design, bringing greater clarity and simplicity to every aspect of the experience

Apple News has an all-new design adding bold typography, vibrant color, and distinct sections that make it easier to find stories on specific topics

Accessing the information you need is easier and quicker with a redesigned Lock Screen and deeper 3D Touch integration

QuickType keyboard adds new emoji, multi-lingual typing, and contextual predictions that leverage deep neural network technology

Suggested events and contact details are added to apps based on information found in Mail

Continue reading





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(@"-----------------------");
    }
}




What’s New in iOS 9.3.2

iOS 9.3.2 fixes bugs and improves the security of your iPhone or iPad. This update:Fixes an issue where some Bluetooth accessories could experience audio quality issues when paired to the iPhone SE.

  • Fixes an issue where looking up dictionary definitions could fail
  • Addresses an issue that prevented typing email addresses when using the Japanese Kana keyboard in Mail and Messages
  • Fixes an issue for VoiceOver users using the Alex voice, where the device switches to a different voice to announce punctuation or spaces
  • Fixes an issue that prevented MDM servers from installing Custom B2B apps

For information on the security content of Apple software updates, please visit this website:

https://support.apple.com/kb/HT201222





How to read MFi Controller input in iOS

Nimbus ControllerI bought a SteelSeries Nimbus controller the other day. It’s Made For iOS (MFi) and supported by many games, including those on OS X and tvOS.

Seriously, it’s a phenomenal controller! Naturally I wanted to see how easy (or difficult) it was to use it in my own projects.

Turns out that for game developers, it’s not that tough to make it work – thanks to Apple’s great GameController Framework that was introduced in iOS 7.

Here’s how I did it, following Apple’s document called Game Controller Programming Guide.

Continue reading