项目中遇到的IOS 9.x兼容性问题总结

对于ios还是有很多陌生,以致项目上了一版本之后才发现,版本适配问题的严重性,总结下这段时间遇到的两个问题。

一:HTMLPrase解析乱码的问题
使用HTMLPrase主要用于解决解析后台懒得解析的html标签,之前一直使用的很顺畅,今天发现9.x系统竟然出现了乱码。最终查到是HTMLPrase出了问题,而且8.x正常显示。可想而之,肯定是编码除了问题。以下是解决方案:
-(id)initWithString:(NSString*)string error:(NSError**)error
{
    if (self = [super init])
    {
        _doc = NULL;
       
        if ([string length] > 0)
        {
            CFStringEncoding cfenc = CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding);
            CFStringRef cfencstr = CFStringConvertEncodingToIANACharSetName(cfenc);
            const char *enc = CFStringGetCStringPtr(cfencstr, 0);
           
            //在这里加上下面两句!!
            char buffer[255];
            if (enc == NULL) {
                if (CFStringGetCString(cfencstr, buffer, 255, kCFStringEncodingUTF8)) enc = buffer;
            }
           
            int optionsHtml = HTML_PARSE_RECOVER;
            optionsHtml = optionsHtml | HTML_PARSE_NOERROR; //Uncomment this to see HTML errors
            optionsHtml = optionsHtml | HTML_PARSE_NOWARNING;
            _doc = htmlReadDoc ((xmlChar*)[string UTF8String], NULL, enc, optionsHtml);
        }
        else
        {
            if (error) {
                *error = [NSError errorWithDomain:@"HTMLParserdomain" code:1 userInfo:nil];
            }
        }
    }


return self;
}

二:获取推送通知设置
IOS7和IOS8的判断方式不同,直接上代码把:
- (BOOL)isAllowedNotification {
    //iOS8 check if user allow notification
    if ([self isSystemVersioniOS8]) {// system is iOS8
        UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];
        if (UIUserNotificationTypeNone != setting.types) {
            return YES;
        }
    } else {//iOS7
        UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
        if(UIRemoteNotificationTypeNone != type)
            return YES;
    }
   
    return NO;
}

猜你喜欢

转载自346520456.iteye.com/blog/2257166
今日推荐