I am investigating integrating Newsstand into a new iOS application, and want to know whether I can do this in a way that will still allow the app to run on devices that have not migrated to iOS 5.
Can anyone give me some feedback on how to architect an application to handle this?
I know it is possible to have a single application with different targets and sets of source files, but I would prefer to keep the codebase as unified as possible, and test for Newsstand features dynamically.
For these reasons, adding a member to an existing interface is considered a breaking change. This is considered breaking for two reasons: It breaks late-bound scenarios such as the late binding feature in Visual Basic and dynamic in C#. It breaks source compatibility when developers use named arguments.
NET Framework 4.5 and later versions are backward-compatible with apps that were built with earlier versions of the . NET Framework. In other words, apps and components built with previous versions will work without modification on the . NET Framework 4.5 and later versions.
What you have to first of all it to weak-link your application to the NewsstandKit framework. This avoids that a device with an iOS version < 5 will crash due to the missing libraries.
Then at runtime you need to avoid calling NK methods and referring to NK classes which obviously are not available in iOS < 5. In such case you can use methods like NSClassFromString() or other obj-c runtime features that allow to detect dynamically the existence of these features.
A recommendation that I can do it in such case is to provide a pre-compiler directive that allows you to isolate all Newsstand stuff at compilation level. In this way you can try to compile using SDK 4 (if you have it) and see for compiler errors or warnings.
E.g. if you add in your Prefix.pch a definition like this
#define WILL_USE_NK
then you can bracket all NK references in this way:
#ifdef WILL_USE_NK
... your NK statements go here ...
#endif
Later, when you will compile the app with SDK4 you keep this definition so you will have a real SDK4 compilation valid for iOS4 devices (that you can test) and you will be sure that all your NK references are not used by an iOS4 app. Then you must #undef this definition and compile with SDK5 (of course keeping some iOS 4.x as minimum target) before distributing the app.
Of course in this way you're not protected against all possible mistakes but at least you have isolated the NK references.
As far as the better strategy about the business logic of the application, this is up to you: it's not an easy task as now Newsstand takes care of many aspects, like background download and so on. Besides the magazine model is now split between your existing model and the NKIssue features, but all these are implementation details that go beyond this specific question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With