Home  >  Q&A  >  body text

objective-c - ios ,关于方法被弃用的问题?

比如,一个方法在iOS8.0 被弃用了,我们都替换成苹果建议使用的方法,那如果iOS8.0之前的版本手机,装上了这个应用。因为8.0之前没有替换后的方法,那调用到这个方法的时候,会不会出现什么问题?

例如:

迷茫迷茫2697 days ago470

reply all(3)I'll reply

  • 大家讲道理

    大家讲道理2017-05-02 09:21:45

    If this method was added after ios8, then if the phone is still running on ios7, an error will occur. This is the same as android and requires manual control.

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-02 09:21:45

    The deprecation is actually just no longer updated. In fact, it can still be used but there will be a warning. If you think manual control is more troublesome, you can still use this method.

    reply
    0
  • 迷茫

    迷茫2017-05-02 09:21:45

    There will be problems and even crashes.

    For the case of method Deprecated, it can generally be handled like the following:

    NSString *sampleString = @"abcdefg";
    if ([sampleString respondsToSelector:@selector(stringByReplacingPercentEscapesUsingEncoding:)]) {
        [sampleString stringByReplacingPercentEscapesUsingEncoding:<#your-encoding-here#>];
    }
    else {
        <#your-else-code-here#>
    }

    reply
    0
  • Cancelreply