Newsstand Integration without Backward Compatibility

I am studying the integration of Newsstand into a new iOS application and I want to know if I can do it in such a way as to still allow the application to run on devices that have not migrated to iOS 5.

Can someone give me some feedback on how to create an application to handle this?

I know that it is possible to have one application with different goals and sets of source files, but I would prefer to keep the code base as unified as possible and test Newsstand functions dynamically.

+6
source share
1 answer

What you need first of all for a weak link of your application to the NewsstandKit structure. This avoids the fact that a device with iOS version <5 will crash due to missing libraries.

Then at runtime you need to avoid calling NK methods and referring to NK classes that are obviously not available on iOS <5. In this case, you can use methods like NSClassFromString () or other obj-c functionality that allows you to dynamically detect the existence of these functions.

The recommendation that I can do this in this case is to provide a pre-compiler directive that allows you to isolate all the materials in Newsstand at the compilation level. Thus, you can try to compile using the SDK 4 (if any) and see compiler errors or warnings.

eg. if you add a definition like this to your Prefix.pch

#define WILL_USE_NK 

then you can copy all NK links this way:

 #ifdef WILL_USE_NK ... your NK statements go here ... #endif 

Later, when you compile the application with SDK4, you save this definition so that you have a real SDK4 compilation valid for iOS4 devices (which you can test) and you are sure that all your NK links are not using the iOS4 Application. Then you must # complete this definition and compile with SDK5 (of course, keeping some iOS 4.x as a minimum goal) before distributing the application.

Of course, in this way you are not protected from all possible errors, but at least you have highlighted NK links.

As for the best business logic strategy for the application, it is up to you: this is not an easy task, as Newsstand now takes care of many aspects, such as downloading phonograms, etc. In addition, the magazine model is now split between your existing model and the NKIssue functions, but all these are implementation details that go beyond this specific issue.

+5
source

Source: https://habr.com/ru/post/900295/


All Articles