Category Archives: iOS

iOS 9 beta 4 OTA

Just a quick note if you are having difficulties installing the new (released July 21) iOS 9 beta 4 on your device via OTA (over-the-air), which prevents you from having to do a Restore. You need to remove any “beta” profiles or WatchOS profiles that might be installed. If you have either of these, delete them (Settings –> General –> Profiles), restart, then go to Settings –> General –> Software Update and the new version will appear. Enjoy!

Creating a Transparent Modal UIViewController in iOS 8

I’ve just started to scratch the surface of all the cool things iOS 8 can do, so much to learn! One of my apps presents a modal view controller that asks the user to select a date from a custom calendar view I built. The app displays photos and this modal vc is presented over an image, so I wanted the modal vc to be (semi) transparent, so the image could be seen behind it. I scoured the web but there seemed to be a lot of conflicting ideas out there and none of them worked for me. I happened to stumble upon a/the solution on my own, while poking around Attributes Inspector.

Select the (modal’s – i.e. the one you want to be transparent) view controller from your storyboard and then click on the Attributes Inspector. As you can see in the screen shot below, there are Transition Style and Presentation options now available. The Transition Style is just what you expect it is and for Presentation, you want to select Over Current Context. Viola! Crazy simple.

Attributes Inspector

I’d be interested to hear what has worked for you in iOS 7, although backward compatibility is quickly becoming less interesting to me.

How To Convert HTML to NSAttributedString

I’m not sure what the best practice is these days when displaying HTML content in your app. It seems you can either put it into a UIWebView or you can, as of iOS 7, convert it to an NSAttributedString and put it into a UILabel, UITextField, etc. I have been leaning toward the latter recently and thought I’d post the 2 lines of code required to make that happen.

NSAttributedString *stringWithHTMLAttributes = [[NSAttributedString alloc] initWithData:[self.htmlText dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute:@(NSUTF8StringEncoding)} documentAttributes:nil error:nil];

self.htmlLabel.attributedText = stringWithHTMLAttributes;

The above code assumes you have HTML stored in an NSString variable called “self.htmlText” and a UILabel called htmlLabel and that your encoding is UTF8.

Let me know if you have any questions or if there is a better practice I’m not aware of.

How to Convert an ISO8601 Date in iOS

I still find working with dates in iOS a little tricky. There is always a new format to deal with and it’s all about getting the identifiers for the format just right! I recently ran into ISO8601 and hope the bit of code below is of some use.

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZZZ"];
NSDate *date = [dateFormatter dateFromString:self.releaseDate];
[dateFormatter setDateStyle:NSDateFormatterLongStyle];
self.dateString = [dateFormatter stringFromDate:date];

You can, of course, pick any other date format style (instead of Long) as the output. As always, let me know if you have any questions.

Handoff in iOS 8 and Yosemite (Beta)

I’ve been trying to get Handoff, one of of iOS 8’s Continuity features, to work since the betas of iOS 8 and Yosemite were available on the Apple Developer Site with very limited success. Now that iOS 8 is GM, it seems to finally work. Here are the steps I took to get it working.

First off, you need to make sure all of your devices are logged into the same Apple ID account. If you tap on the Settings app and scroll down to iCloud, iOS 8 now shows you which Apple ID you are logged in with, very handy. Same for OS X Yosemite, go to Settings > iCloud and on the left side beneath your photo is the active account. This was the case for me, so I moved on to the next step.

The main problem I had was my Mac and my iPad were not showing up in my iPhone’s Bluetooth settings panel. Restarting both my iPad and iPhone, as well as toggling Bluetooth off then on seemed to solve this issue. Note: It can take your iPad or iPhone a LONG time to see other devices (e.g. Mac, iPad, or iPhone) via Bluetooth, so you have to be patient.

Once both devices were restarted, all my other devices started to show up in the Bluetooth settings area. If this isn’t the case, try restarting again. Once you “see” them in Bluetooth settings, Handoff will work.

Of course, Handoff only works with apps that support this feature, such as Maps, Messages, Mail, Safari, Calendar, etc. I’ve already seen third party apps supporting it, so make sure to update (ideally via auto update) the apps on your devices. Also, I’ve only been able to activate Handoff (for iOS devices) from the Lock Screen. Maybe this is how it works. I really like how OS X Yosemite handles it, with a new icon on the left end of your Dock. If you know how to activate Handoff other than from the Lock Screen, I’m all ears!!!

[In iOS 8, a “grey” icon appears in the bottom left corner of the lock screen of your device. Swipe up (and possibly enter your passcode) to active Handoff.]

Finally, there still seems to be a few glitches. I noticed my iPhone or iPad didn’t always show the icon for the app I had activated on my Mac. For example, I’d bring Mail to the foreground, check my iPhone’s lock screen and see the little (grey) Mail icon in the lower left. Then I’d switch to Safari on my Mac. Sometimes the iPhone would update the icon to Safari, sometimes it wouldn’t. However, I’m sure this feature will just get better in future updates. For now, I’ve been able to get it work between Mac and iOS devices and between multiple iOS devices.

Not rocket science but hopefully this helps.