Weak linking on iPhone refuses to work

后端 未结 2 837
抹茶落季
抹茶落季 2020-12-01 11:20

I\'ve got an iPhone app that\'s mainly targetting 3.0, but which takes advantage of newer APIs when they\'re available. Code goes something like this:

if (UI         


        
相关标签:
2条回答
  • 2020-12-01 11:24

    Here is what I had to do when checking for an external framework constant.

    const CLLocationAccuracy * ptr = &kCLLocationAccuracyBestForNavigation;
    BOOL frameworkSupports = (ptr != NULL);
    if (frameworkSupports) {
        return kCLLocationAccuracyBestForNavigation;
    } else {
        return kCLLocationAccuracyBest;
    }
    

    It would not work without the ptr variable.

    0 讨论(0)
  • 2020-12-01 11:49

    Aaand I figured it out. For symbols that are not functions (extern const int foobar, for instance), you have to compare against the address of the symbol, not the symbol itself, so:

    if (&UIApplicationWillEnterForegroundNotification != NULL)
        etc;
    

    Which in retrospect is kind of obvious, but I still fault the entire universe around me for not ever mentioning the distinction.

    0 讨论(0)
提交回复
热议问题