简体   繁体   中英

Is my update okay for iOS 3.0 users (I check if Core Telephony exists)?

Detail : I am ready to submit an update to my app to Apple. However, I have one area of doubt. I have added the following code in the header of one of my classes ...

#import <CoreTelephony/CTTelephonyNetworkInfo.h>

and this in the main class ...

if ([CTTelephonyNetworkInfo class]) {
    //Now do some telephony stuff ...

Telephony is for iOS 4 and above. I believe that anyone still on iOS3 should be fine because of the if statement, but I can't test it because I dont have an old device and XCode 4.2 doesn't have an old emulator.

My iOS Deployment target is still 3.0, and I'd preferably like to keep it that way to ensure everyone can use my app.

Question : Is my code correct? Is my iOS Deployment Target correct? Am I going about this in the correct way?

No it's not.

if (NSClassFromString(@"CTTelephonyNetworkInfo") != nil)
{
    // use class
}
else
{
    // not available, deal with it.
}

Is what you should use. Using what you wrote the app will just crash as it wont find CTTelephonyNetworkInfo class. Also you should make sure that you've set the CorTele... framework as optional.

The code is correct (As @SimonH points out, you used to need a NSClassFromString , but that changed with some version of the compiler, by the time the 4.0 SDK was released).

You also need to make sure you weak link CoreTelephony (or for that matter any framework not available on 3.x), so the binary won't attempt to load it when launching the app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM