iOS 7 Wishlist

I’m pretty sure everyone of us that uses iOS always has a wishlist for the upcoming version. I’ll keep mine simple. Those are the top 8 things that I wish to have in iOS 7.

  1. Better sharing between apps (hint: Android)
  2. Ability to set default apps
  3. A better email app
  4. A better camera app
  5. Quick access to settings like turning on/off Wi-Fi & Bluetooth, changing brightness, etc…
  6. More options for organizing home screens
  7. Airdrop
  8. Automatic app updates

What are yours?

AFNetworking, NSURLCache & iOS 6

NSURLCache can be used to define memory and disk caching for URL requests. If you make a connection while you are not connected to the internet with the cache policy set to NSURLRequestReturnCacheDataElseLoad, data should be returned from the cache if it exists. This works as expected on iOS 5 and cached data is always returned. On iOS 6.x, however, this doesn’t happen and the connection will fail returning an error code -1009 which indicates that you are offline. I ran into this recently while using AFNetworking and apparently this is a bug in iOS 6.x and has already been reported to Apple by multiple people.

To workaround this, I wrote a simple class that subclasses AFNetworking‘s AFHTTPClient (thanks to this GitHub issue) and ensures that you always get cached data when it’s available regardless of whether you are connected to the internet or not.

What it does is that it gets the NSCachedURLResponse in the failure block of the request you are making and deserializes it using NSJSONSerialization, then calls the success block with the responseObject as if the connection didn’t fail.

I’ve added the code to a GitHub gist. Please fork it if you think there’s something that could be improved.

Transform Properties of an NSObject Into an NSDictionary

I needed a way to transform all the properties of an object that are not nil into an NSDictionary. I didn’t find a quick way to do it so I wrote my own NSObject category.

It uses the Objective-C runtime and the idea is really simple. I get a list of properties of the object’s class, loop on them getting their value, and only add them to the dictionary if they are not nil.

Google Currents-style UISegmentedControl

Introducing HMSegmentedControl, a drop-in replacement for UISegmentedControl mimicking the style of the segmented control used in Google Currents for iOS.

Grab the code from GitHub: https://github.com/HeshamMegid/HMSegmentedControl

Usage

The code on GitHub includes a demo project showing how to use the control.

To use in your own project, first import HMSegmentedControl.m and HMSegmentedControl.h into your project, then add QuartzCore to your linked libraries.

The code below will create a segmented control with the default looks:

1
2
3
4
5
HMSegmentedControl *segmentedControl = [[HMSegmentedControl alloc] initWithSectionTitles:@[@"One", @"Two", @"Three"]];
[segmentedControl setFrame:CGRectMake(10, 10, 300, 60)];
[segmentedControl addTarget:self action:@selector(segmentedControlChangedValue:) forControlEvents:UIControlEventValueChanged];
[segmentedControl setTag:1];
[self.view addSubview:segmentedControl];

If you used this code in your project or it was helpful to you, I would love to hear from you!

Get international Dialling Code for the User’s Current Location

In an app I’m working on, users are supposed to enter their phone number including the international dialling code. I know this could be confusing for some users that are not so sure about the dialling code so I wanted to insert it automatically.

So I’ve created HMDiallingCode, a light weigh library that gets the dialling code of the user’s current location. It uses CoreLocation and reverse geocoding to determine the country of the user, then retrieve it’s international dialling code from a plist.

The code is available on GitHub at https://github.com/HeshamMegid/HMDiallingCode