suchen

Heim  >  Fragen und Antworten  >  Hauptteil

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

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

例如:

迷茫迷茫2862 Tage vor566

Antworte allen(3)Ich werde antworten

  • 大家讲道理

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

    如果这个方法是在ios8后加入的,那么如果手机还在ios7那么运行就会出错,这点和android相同,需要人为的去控制。

    Antwort
    0
  • 仅有的幸福

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

    弃用其实只是不在更新了,实际上还是可以使用的只是会有个警告而已,如果认为人为控制比较麻烦还是可以使用这个方法的.

    Antwort
    0
  • 迷茫

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

    会有问题,甚至会造成 crash。

    对于方法 Deprecated 的情况,一般可以类似下面处理:

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

    Antwort
    0
  • StornierenAntwort