What Do You Do When Your ObjC Completion Handler Needs To Retry ?


Objective C

I've been coding against Facebook's Graph API the past few days, and it turns out - not unreasonably - that like Twitter, some of their error messages request you to retry (or to back off, wait and retry if you're a good web citizen and don't want to get your App hell banned).

This is easy peasy in synchronous code, you just loop and increment some counters and you're done, but in today's asynchronous world, things get a little trickier. Many async APIs require you to provide a completion handler and when you get a back off/retry error in your completion handler, you have to issue your request again, which means you have to pass - you guessed it - your completion handler. Which means you're recursing. Recursive blocks are allowed, though you might have a bit of a 'mare figuring out the syntax that allows them (or indeed, to do anything else with them).

Here's a pattern that i came up with this afternoon. I'm sure there's all sorts wrong with it, and it will likely blow up in the first bit of real world code I use it in, but it chunters along happily in its Foundation CLI tool, and it doesn't issue any compiler warnings. Food for thought at least.

And no, I'm not at all sure about that sleep() either. Share and enjoy :-)

Update Thu 26 Jun 2014 (original code)
I worked on this a bit more this morning and got rid of some of the __weak / __strong dance line noise. For context, I'm basically mocking out a small part of FB's graph API here, I'll post full code when I've integrated and tested it. It will still be pretty ugly, much uglier than this nice clean(ish) POC, I imagine.



Comment Alert Bork


Beaker from the Muppets

Apologies to anyone who's left a comment and I've not replied or acknowledged. Somewhat annoyingly, the gmail account that I use to interact with Disqus has decided to file all communications from Disqus in the spam folder. I'm sure this was just a mistake, eh ?



Finding Out What Version Of Your iOS App Was Originally Installed : Part 2 – The Ugly Way


ios_tag

In part 1 I wrote up a method of finding out what version of your iOS app a user originally installed that works great, provided you can get a network connection and the App Store servers are up.

But if you can’t rely on that being the case, and you don’t want to wait for it to be true before you take whatever action you’re basing on the original version number, you can get the receipt data locally and process it.



Finding Out What Version Of Your iOS App Was Originally Installed : Part 1 – The Easy Way


380_wpm_lowres

So, for whatever reason – lets say that you want to experiment with a free download and IAP monetization model in an existing paid app but you don’t want to double charge existing users, or maybe you need to do some clever user defaults or data model updates – you decide that you need to know what version of your app was originally purchased.

So far as I’ve been able to discover so far, there are basically two ways to go about this. Well, one way, but there are two ways of getting the data. Well, N ways actually, but let’s not get all forked up at this point. This is (one possible implementation of) the easy way.

Assuming you have a receipt (and you may well not, in your dev version at least, in which case you need a bit of SKReceiptRefresh magic) then you can find it in your app’s bundle, and (assuming you have some network connectivity, and can talk to it) you can fling it at the App Store servers and they’ll parse it for you and fling back some JSON.

It looks a little like this.



Detect If WiFi Is Enabled On iOS With This One Weird Trick


ios_tag

Before I show you the one weird trick, a caveat or two. There isn’t a framework method anywhere to do this, and while this code doesn’t involve touching any private APIs it does have a number of other issues. From an app store review perspective, it could easily be argued that if Apple wanted you to be able to detect this stuff, they’d have put an API in for you. While I do intend to try it out, I suggest that if you do use this code in a production app you ready yourself for rejection and have a backup plan. From a technical point of view, it seems likely that you will need that backup plan as this possibly rather less than robust. I’ll get to that in a minute, you want to see the code now right ?



SKRequest With Blocks


Objective C

I like C blocks and I cannot lie. Which is just as well, really, since so much of the iOS SDK is built that way. They don’t come without their own idiosyncratic set of problems though, one of which is that so much of the iOS SDK isn’t built that way. Maybe it’s just my bog standard codemonkey OCD spiking, but I sometimes find that when I’m deep into some bit of block based coding and going all data flowy and functional, dropping back to the objecty world of message passing and delegate protocols at an inappropriate point in my flow can lead to a lot of mental gear grinding and lo, gnashing of the teeth.



Phoreal Launched


Havelock+WIndows_promo_shot_02

So finally, we shipped something! Enigmatic Ape is proud to announce the launch of our first iOS 7 app, Phoreal.

Phoreal is a small photo utility app that was written specifically to scratch an itch we had. Transferring photos over to some machines from iOS 7 resulted in the loss of our lovely filters. Then an associate started using an iPhone with Windows and noticed that many of the photos copied over from the iPhone's DCIM folder were the wrong way up (there'll be a technical blog post about why these things happen coming up shortly).

And so Steve wrote Phoreal to save copies of correctly filtered and rotated photos to the iOS 7 camera roll where they can be easily synced over to Windows machines and older macs.

Even though it's a super simple app, we plan to update it with some new features and options in the near future, and of course, we'll be fixing any bugs that come up.

Here's a video we made to show how Phoreal works. To learn more about Phoreal click here. Or download on the app store!





SOLVED – Returning A Block From An OCMock Stub


Picture iof text which reads [ObjC]

Problem

You want to return a block from an OCMock stub method, something like this :

[[[the_mock stub] andReturn:the_block] method];

That should work, right ? According to the blocks docs :

Blocks are Objective-C objects, which means they can be added to collections like NSArray or NSDictionary.

But it doesn’t work, and OCMock throws you an exception along the lines of Expected invocation with object return type. Did you mean to use andReturnValue: instead?



Fixing Git SSH Errors With Jenkins On OS X


generic picture of a keyboard

The Problem

So you installed Jenkins on OS X using the .pkg installer (you’ll regret that, I promise), you’ve set up all your SSH keys correctly on the server and client – at least, you think you have, see later – but when you try and point a new job at your git repo, you get an error, like this one :

Permission denied (publickey,gssapi-keyex,gssapi-with-mic,keyboard-interactive).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Or this one :

Failed to connect to repository : Command "git ls-remote -h ssh://git@localhost/Users/git/Repos/HelloCI/ HEAD" returned status code 128:
stdout: 
stderr: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,keyboard-interactive). 
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.



Introducing Phoreal – get your iOS 7 filters back


photo

One of the features of iOS 7 that I really like is the new filters in the camera and photos apps. With a choice of Mono, Tonal, Noir, Fade, Chrome, Process, Transfer and Instant and the new square format, you can create some really great looking pictures.

The way iOS 7 applies these filters to the photos is clever. Rather than simply computing the output of applying the filter to the image and storing the result, iOS 7 saves a bunch of meta data about which filter was selected and what (if any) cropping has been done along with the original image.

Then, when you view the pictures in the camera app, share them via social media or send them by email, iOS 7 applies the relevant filters and crops in real time. Our phones are that fast now that they can do image processing on the fly.

This also means that if you change your mind later and decide that Tonal is more appropriate than Noir for dramatising your architecture shots, you can simply change the filter.

The whole process is non destructive. You can chop and change filters and crops to your heart’s content because the original image is always preserved.

In typical Apple fashion, for a huge majority of typical use cases, this just works. And it works flawlessly and transparently. If you’re not in the majority though, you may find that it causes issues for your atypical workflow.

In my case, for instance, I went crazy for square format black and white, and ended up with more than 900 photos shot that way before I realised that when I was syncing them back to iPhoto on my Mac, I was ending up with the originals with no filters applied.

If your photo workflow involves a step where you sync your images back to a Mac,PC or cloud service you’ve probably noticed the same thing. You’re ending up with copies of the original image with no filter applied.

This is the problem I wrote Phoreal to solve. Phoreal reads the meta data that iOS 7 stores, applies your selected filter and crops, and saves a copy of the resulting image back your camera roll. The images that Phoreal outputs can then be synced to your Mac, PC or cloud data service in all their filtered glory.



Touch Me – Affordance in iOS 7


ios7icon

If you’ve worked in or studied UI design – or, if you’re a bit longer in the tooth like me, Human Computer Interaction – ‘Affordance’ is a term that you’re probably quite familiar with. Wikipedia gives the basic definition as :

An affordance is a quality of an object, or an environment, which allows an individual to perform an action. For example, a knob affords twisting, and perhaps pushing, while a cord affords pulling.

If you’ve done the HCI/UI thang though, what you’re probably more familiar with perceived affordance as defined by Don Norman in The Design Of Everyday Things, which is a much more context dependent kind of a concept.




Built With Bootstrap
Powered By Wordpress
Coded By Enigmatic Ape