问题描述

运行项目到ios12.2设备上直接闪退,在xcode上调试,发现以下错误:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key _alwaysRunsAtForegroundPriority.'

问题分析

出现这个问题的主要原因是cordova-plugin-background-mode插件的问题。主要使用了私有api接口_alwaysRunsAtForegroundPriority 需要修改为alwaysRunsAtForegroundPriority

问题解决

找到插件cordova-plugin-background-mode/src/ios/APPBackgroundMode.m 中,修改

+ (NSString*) wkProperty
{
    NSString* str = @"X2Fsd2F5c1J1bnNBdEZvcmVncm91bmRQcmlvcml0eQ==";
    NSData* data  = [[NSData alloc] initWithBase64EncodedString:str options:0];

    return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
}

成:

+ (NSString*) wkProperty
{
    NSString* str = @"YWx3YXlzUnVuc0F0Rm9yZWdyb3VuZFByaW9yaXR5";
    NSData* data  = [[NSData alloc] initWithBase64EncodedString:str options:0];

    return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
}