Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recommended way to test for iOS Version specific feature at runtime

I'm targetting IOS 4.3 and 5.0 with an app built against the 5.0 SDK and would like to add support for the Twitter functionality introduced in iOS5 only when the app runs on a iOS5 device. What is the recommended way to reliably test for the availability of these OS features at runtime without having your app crash?

I know you do this using respondsToSelector in Objective-C but how is it done in C#?

like image 447
Oliver Weichhold Avatar asked Nov 29 '11 13:11

Oliver Weichhold


People also ask

How do I find my OS version in Objective C?

In Objective-C, you need to check the system version and perform a comparison. [[NSProcessInfo processInfo] operatingSystemVersion] in iOS 8 and above.


1 Answers

Follow up to comments, including mine...

If you want to check by feature you can do something like:

        MonoTouch.Twitter.TWRequest req = new MonoTouch.Twitter.TWRequest ();
        if (req.Handle == IntPtr.Zero) {
            Console.WriteLine ("No Twitter support before iOS5");
        }

What happens is that the selector to create the TWRequest instance will return null and the .NET object will be created in an invalid (unusable) state that you can query with the Handle property. Again YMMV, testing is key :-)

like image 121
poupou Avatar answered Nov 15 '22 22:11

poupou