Category Archives: iOS

Container View Controllers in Swift

If you are using a ‘Container View’ in Xcode’s storyboards it’s likely that you want to get a handle to the view controller you create inside the container view. Surprisingly, there isn’t an obvious way to do this. However, you can use the ’embed segue’ to find the handle to the container views because when the container view is added the embed segue is called. So when you create the container view give the embed segue a unique identifier and then you can grab the handle to your view controller in the prepareForSegue method as follows…

var myController: MyController?
var myOtherController: OtherController?

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    guard let ident = segue.identifier else {
        return
    }
    switch ident {
    case "MyEmbedSegueIdentifier":
        myController = segue.destinationViewController as? MyController
    case "MyOtherEmbedSegueIdentifier":
        myOtherController = segue.destinationViewController as? OtherController
    default:
        break
    }
}

Stripping print and debugPrint in Swift for release builds

When building an app for release with Swift you should make sure that any of the print and debugPrint statements you used when building and debugging the app are disabled.  The reason for this is that if you leave them in then they will unnecessarily slow down the app since every write to console output takes time.

In Swift you can easily do this by redeclaring the print and debugPrint functions using these two lines of code…

func debugPrint(items: Any..., separator: String = " ", terminator: String = "\n") {}

func print(items: Any..., separator: String = " ", terminator: String = "\n") {}

We simply declare the functions again but with empty implementations of {}.  When you’re building and testing your app just comment these two lines, but when complete make sure you uncomment them before release.

You should place these two lines at the top-level of your code.  That means, do not put it inside a class, extension or protocol declaration.  A good place to put them is at the top of your AppDelegate file, before the AppDelegate class and not inside it.

Alternatively, simply create a brand new Swift file in your project and call it something like ‘ReleasePrint.swift’ and put the code in there.  Basically, it can be anywhere as long as it is top-level and not inside another class.

Finally, you may find it useful to always see the output from print and debugPrint in the simulator, but never on the device.  If you want to do this you can use the architecture flags to automatically turn the output on and off as follows…

#if !arch(x86_64) && !arch(i386)

func debugPrint(items: Any..., separator: String = " ", terminator: String = "\n") {}
func print(items: Any..., separator: String = " ", terminator: String = "\n") {}

#endif

WiFiFoFum Intrepid

I’ve been working on a new version of WiFiFoFum with Malc.  The codename we’ve used for the project is Intrepid, and it’s basically a complete rewrite of the WFFF codebase to get it compatible with iOS 7.

As many of you will know, WFFF for iOS has languished for some time due to Apple’s policies around Wi-Fi scanning.  Years ago WFFF was kicked out of the official App Store and we subsequently put it in Cydia.  Although it found an audience in Cydia, it got harder and harder to develop the app when Apple were not only denying us access to the iTunes Store distribution channel, but also seemed to be doing everything they could to block developers from accessing the Wi-Fi functions in iOS devices.

Dynamically Loaded felt it was time to try to push the boundaries again and, thanks to some simply stunning and ground-breaking work from Malc, he and I have created a version of WFFF that works wonderfully on standard iOS 7 devices… no jailbreak required!

I’m particularly proud of Intrepid.  A decade ago Malc and I were the first to figure out Wi-Fi scanning on Windows Mobile devices, and released WFFF as the world’s first widely available, mobile wireless scanner.  Half a decade ago we were the first to discover how to achieve Wi-Fi scanning on the iPhone, which led to the first iOS version of WFFF.  When Apple changed the Wi-Fi frameworks a couple of years later we again were the first to discover how to scan using new techniques.  Finally, when Apple completely removed Wi-Fi access via the iOS frameworks, even when using the hidden techniques we had discovered, I thought we’d never again be able to provide Wi-Fi scanning on jailed iOS devices.  However, with Intrepid we’ve done it, and I can’t wait to release it publicly and make the world’s best Wi-Fi scanner available to all iOS devices once more.

Our new scanning methods do not break ANY of the iTunes App Store rules so we will be submitting it to Apple and hope to have WiFiFoFum Intrepid available through the official store.  However, there are never any guarantees with Apple, so if for any reason they do not allow it into the store we will be making it available directly through the Dynamically Loaded site.

Intrepid will be ready for release soon, but in the meantime here are some screenshots of it running on my own jailed iPhone 5.

iOS 7 thoughts

I am both excited and scared about the upcoming iOS 7 release.  Excited because it’s a chance for Apple to introduce many new and innovative features, and scared that if Apple don’t do this then we could see iOS sales really struggle for the next cycle.

iOS 6 was a relatively small update over iOS 5.  Whilst iOS 5 brought us some hefty new features like iCloud and Siri, iOS 6 brought much smaller improvements, and its main novel feature was the change from Google to Apple for Maps.app, which suffered some serious issues at launch.

If Apple follows its typical timeline for major iOS updates then it’s likely we’ll see the first developer previews of the next major update, iOS 7, in the next couple of months.  Given the increased competition Apple is seeing from the latest versions of Android, I believe iOS 7 has to be a significant upgrade with many new features. Apple have let iOS somewhat stagnate over the last few years, and they have to address that now.

When Steve Jobs first showed the iPhone he boldly stated it was 5 years ahead of the competition.  It’s been over 5 years since its release now, the competition has caught up, and Apple have to innovate with this update.  The new hardware this year will be incremental updates, with the iPhone 5S, a retina iPad mini, and minor form factor changes to the full-size iPad.  So, this is an ideal year for Apple to focus on their mobile software.  With a major change in iOS management, the departure of Scott Forstall, there must surely be momentum for not only a substantial software update, but room for a change in the ethos of iOS.

I expect to see a lot of major changes, and I have an extensive wishlist of improvements and new features that would take pages to write out, but what follows is a condensed list of what I think are reasonable guesses for what we could potentially see in iOS 7.

Integration

For a long time Apple has boasted of not just the ease-of-use of their devices, but of easy integration between devices.  In iOS, there is a great deal that could be improved in this area.  For example, many of us now own both an iPhone, an iPad and a Mac, or some combination of these.  However, when a call comes in on an iPhone, there is absolutely no notification of it on the iPad or Mac.  For me, this is often frustrating.  Sometimes whilst at home I leave the phone in one room whilst I’m on the iPad or Mac in another.  When my phone rings in the other room I don’t hear it, and even although I’m holding my iPad or have my laptop on my lap there is no notification to tell me who is calling.  By simply having the iPhone send a push notification to your other devices in this situation you would never unintentionally miss a call.

A slightly different, but annoying, behaviour occurs just now with FaceTime calls.  When I receive a FaceTime call all my devices ring, which is great.  However, if I answer the call on my iPhone then later on when I pick up my iPad it still has a notification that says one missed call.  However, the call wasn’t missed, I did answer it on my iPhone.

There’s so much more that could be done with improving device-to-device integration in iOS, but I think these are two good, basic examples of where some improvement could be easily implemented.

Remote

I am confident Apple is going to release a full television product, and when they do I think iOS devices should integrate with it to be a remote and a second screen.  I would expect iOS 7 to either have this functionality, or at least the seeds of it.  iOS devices should be able to perform as a remote and/or second screen for Apple TVs in a much more functional manner than they currently do.  For example, when viewing a movie on an Apple TV the iOS device should not just allow you to perform the standard remote controls such as play, pause, forward, rewind.  The device should also show additional useful information and functions.  For example, information about the movie, genre, actors, social functions where you can comment on the movie and participate in discussion.

Quick Access to Settings

I frequently use the Do Not Disturb feature that iOS 6 introduced to silent my phone.  However, accessing the setting that turns this on and off is slow and frustrating, primarily because I first have to find the Settings app.  Similarly, turning Wi-Fi on and off is slow.  Indeed, it is worse as it isn’t at the root level in the Settings app so you have to go into the Wi-Fi section to find the on/off toggle.  Commonly changed settings such as Do Not Disturb, Wi-Fi and Bluetooth power should be easily accessible from the Notification Centre pulldown.

Multitasking Improvements

I’m not sure about this one, as Apple has invested a lot of time and effort in creating a backgrounding system based on apps requesting the right to run in the background as they get location updates or play audio.  However, there are so many reasons for apps to run in the background that Apple have failed to anticipate and have been added in an ad hoc manner over the years that I think it’s time they just gave up and let apps run in the background if they like.  They could still require that users have to give permission for apps to do this, but instead of trying to section backgrounding into location, audio, VoIP the app could simply ask for background permission, which would allow apps to get the right to execute in the background for any reason, rather than just the ones Apple are able to think of right now.  A good example of a reason to run in the background that Apple hasn’t anticipated is to monitor the accelerometer.  I’ve tried to get an app to do this to track user activity levels for a fitness app, but since when it comes to movement Apple only anticipated the need for location backgrounding, an app that wants to track activity simply can’t run in the background (unless it also requests permission for another reason that is sanctioned by Apple, such as location).

Open Up the System

The jailbreak community is still thriving.  Just 24 hours after the release of the Evasi0n jailbreak there were over 1 million people who had used it.  Whilst I don’t normally have my own iOS devices jailbroken, there is a clear demand for it.  Although having iOS tightly locked down initially benefited Apple as they first began releasing iPhones, it’s time they opened up access to the device and OS more for developers.

Android is relatively open, and this allows developers to provide many novel and exciting apps that just aren’t possible in iOS.  Apple have already implemented a solution in OS X where users can decide to allow apps from the Mac App Store only, developer-signed apps, or any apps.  iOS should have the same settings in order to allow users to feel absolutely secure in using iOS Store Apps, whilst at the same time allowing them to experiment with the bleeding edge apps if they so desire.

Readster

I’ve just released a new RSS app called Readster.  I designed and created it with Malc.  We spent a long time thinking about how best to display news in a beautiful yet intuitive way, and I really think we achieved it.  As part of the app I also created a full-screen in app web browser mode, similar to Safari in iOS 6.  Pretty pleased with the way this app turned out.  If you are interested you can grab it by clicking here.

Why Apple will build a ‘cheap’ iPhone in 2013

There has been a great deal of discussion around whether Apple will release a cheaper iPhone or not. Many of those who say Apple won’t, seem to believe that to do so would mean Apple are cheapening the brand. Many of the rumors talk of such an iPhone being made of ‘cheaper materials’, such as plastic, and this implies a low-quality product.

I disagree, and I’m almost positive Apple will release a cheaper iPhone in 2013. The argument that Apple will not release a cheaper version starts to fall apart when you look at the company’s product history. Indeed, it’s hard to see a product other than the iPhone for which Apple has not offered less expensive options. Going back to the early iPod lineup, Apple released the iPod mini just three years after the original iPods. These were designed to be cheaper, and certainly had less storage than the fullsize iPods of the time. The original iPod when it came out in 2001 had 5GB of storage, and by 2004 when the iPod mini was released the standard iPod line was coming in 20 and 40GB versions. The first iPod minis had 4GB, less storage than the 3 year old original iPod. Many said nobody would buy it, yet the iPod mini quickly became a massive success, outselling the fullsize iPods.

Similarly, with the laptop lines, Apple has always offered at least a few options. We’ve had combinations of iBook, MacBook, MacBook Pro, and MacBook Air over the last decade, all with vastly different form factors, prices, and features.

A more recent hardware example is the iPad. Only this year Apple released the iPad mini, which looks to now be outselling the fullsize iPad. The fact that Apple are releasing cheaper versions of devices does not scare me at all. The iPod minis were a staggering success story, and it looks like the iPad mini is similarly off to an amazing start.

So, if you look at the hardware, the iPhone stands out because it is really the only Apple device that doesn’t come in multiple offerings. Remember, the iPod mini came out only three years after the fullsize iPod. It’s been six years now since the original iPhone came out… I think we’re overdue for a smaller, or cheaper version.

A second point is that, to Apple, cheaper does not mean low-quality. When the iPod mini came out it was in brushed metal rather than the plastic of the fullsize version. It felt like, and was, an extremely high-quality device. When the iPod nano came out it reverted to plastic again, and yet it too felt high-quality device, and started to outsell the iPod mini. Whether metal or plastic, Apple’s products never feel low-quality.

Finally, with Apple expanding into China the time is right for a lower-cost iPhone. The mobile phone market in China is very different than the US. Most customers save up and buy their mobile phones outright, and are not on contracts that subsidize the purchase price.

So, I certainly think a lower-cost iPhone is coming. Whether this is the iPhone mini or goes by a different name doesn’t really matter, but I do think it will be here in 2013. If it is, the most likely release date would be around the release of iOS 7, as this would allow for the major point update in the software to include many changes that may be required for such a device. This would place the release date sometime in summer 2013. iOS 7 betas are likely to start being seen around April or May, and when they are I’ll be examining the files in it to see if I can find any mention of new iPhone devices.

Examining iOS 6 Maps

I had a quick look at the way Apple’s new Maps app works in iOS 6 with my friend and colleague Malcolm Hall.  We’ve learned a few things by doing some simple tests.

We know Apple has use Yelp’s data to populate its maps with businesses.  Malc noticed that a restaurant near him in San Diego was mislabelled, the ‘Pacific Beach Fish Shop’ was labelled as an actual shop when it is, in fact, a restaurant.  He logged into Yelp and updated it with the correct label, marking it as a seafood restaurant rather than a shop.  Checking back a while later, we can see that on Yelp the business category is updated…

 

However, in Apple’s maps the business is still listed as a shop, with a yellow shop marker showing a basket, rather than the brown dining marker with the fork and knife (you can see an example of that marker at the top-right of the map)…

The fact that Apple’s map didn’t update whilst Yelp’s did tells us that Apple is using a static version of Yelp’s data.  That is, at some point Yelp essentially provided Apple with a dump of a snapshot of their database, and now unless Apple do something to update it themselves then the data will be getting outdated.

Next I checked the accuracy of Apple’s data positioning.  I noticed that nearly all items near me are mispositioned in Apple’s maps.  For example, in the image below you can quite clearly see that ‘Hardie for Peugeot’ should be quite a bit nearer the top of the map at the building surrounded by all the parked (Peugeot) cars.  Additionally, the brown dining marker is for Enrico’s chip shop, which is actually right on the corner of Main Street and Foundry Loan.  It should be exactly where I dropped the purple pin.  The yellow arrows show where the markers should be moved to.

Remember, Apple have got this data from Yelp, so we can easily to see if the mispositioned items are caused by Apple or Yelp by simply checking the data on Yelp.  Checking Enrico’s in Yelp gives this:

Yelp clearly have the location of Enrico’s spot on, positioning it right on the corner of Foundry Loan and Main Street where it should be. Thus, the problem is not with the data that Yelp hold and have supplied to Apple, the problem is with Apple’s copy of the data.  Most likely, Apple have either made an error when copying the data into their own system, or the database they are using has the wrong field type set.

So, this quick examination has shown two things.  Firstly, that Apple has a static copy of Yelp’s data; that is the Yelp data inside Maps app is not being updated live.  Secondly, that Apple have messed up some of the data they received from Yelp either during transmission/conversion, or through a mistake in storage.

Perhaps Apple will get periodic updates of data from Yelp.  For example, maybe they have a contract with Yelp that gives them updates every three months, and so at some point the Pacific Beach Fish Shop in Apple’s data will be updated with fresh information from Yelp and suddenly change to the brown dining marker in Maps.app.  Another possibility is that Apple now think they can do this work themselves, or at least get iPhone users to do it on their behalf.  However, given the strong Yelp branding in the Maps app I doubt this is the case, at least not in the short term, and they are more likely to be hoping they can rely on periodic updates from Yelp.

 

 

 

How to turn off shared calendar alerts in iOS 6 and above

iOS 6 has a new feature where if you are using a shared calendar and someone else makes any change – creates a new event, moves and event, changes length of event, etc – then you will get an alert on your iPhone or iPad. Personally, I find this very annoying as often the people I share calendars with add or edit tens of events at a time and my iPhone just keeps beeping away like crazy.

I eventually figured out how to turn this alert off. Just go to the Settings app, scroll down and select “Mail, Contacts, Calendars”, then scroll down again until you see the “Shared Calendar Alerts” setting and just flick it off. Now your phone won’t have a fit when other people add or edit calendars.

Shared calendar alerts off switch

How to handle ‘No previous prototype for function’ warnings in Xcode

When compiling code in Xcode 4 you may be seeing warnings saying ‘No previous prototype for function…’.  This is probably happening if you are using a library that has at least some parts written in C/C++.  This warning may even be appearing in code that previously compiled fine in Xcode 3 without any warnings.  This is because Xcode 4’s default compiler warns about this when Xcode 3’s did not.

Anyway, the warning is simply saying that a function implementation exists but no matching function declaration was found.  If you are used to Objective-C only this is like saying that you have the implemented code in the .m file but you don’t have the function listed in the .h.  It’s easy to fix, just write the method declaration in anywhere before the actual method; you can write it in the .m or .h, it won’t matter as long as it’s before the actual function.

For example, if you have a method such as…

float doSimpleMaths(float a, float b) {
   return (a*a)*(b*b);
}

Then to get rid of the warning just add in the method declaration before the method…

float doSimpleMaths(float a, float b);
float doSimpleMaths(float a, float b) {
   return (a*a)*(b*b);
}