美文网首页
xcode11适配问题汇总

xcode11适配问题汇总

作者: AllenMu | 来源:发表于2020-02-04 15:27 被阅读0次

因为之前项目中包含大量swift3.0的代码,一直使用xcode10.2没有时间升级,最近swift升级到4.0后,xcode版本也升级到最新的xcode11.2,发现出现一些适配的问题,主要发现以下几类:

视频播放库MPMoviePlayerController废除,导致闪退。

解决办法:视频播放库改为AVKit库下面的AVPlayerViewController。

UITextField私有属性闪退

iOS 13禁止使用kvc修改私有属性,之前一直使用kvc修改UITextField的palceholder,但是iOS13直接崩溃。

[textField setValue:textColor forKeyPath:@"_placeholderLabel.textColor"];
[textField setValue:font forKeyPath:@"_placeholderLabel.font"];

解决方法:设置textField的attributedPlaceholder属性进行设置。

NSAttributedString* attrString = [[NSAttributedString alloc]initWithString:placeholder attributes:@{NSForegroundColorAttributeName:textColor,NSFontAttributeName:font}];

textField.attributedPlaceholder = attrString;

TabBar中选中颜色在页面push后返回颜色变为蓝色

旧代码使用如下:

/**

设置tabbarItem的字体

@param tabBarItem tabbar

*/

- (void)initTitleWithAtrributions:(UITabBarItem*)tabBarItem{

    NSDictionary *noramalAtributes = [NSDictionary dictionaryWithObjectsAndKeys:

                                      [UIColor darkGrayColor],NSForegroundColorAttributeName,[UIFont systemFontOfSize:13.0],NSFontAttributeName,

                                      nil];

    NSDictionary *selectedAtributes = [NSDictionary dictionaryWithObjectsAndKeys:

                                      [UIColor colorWithHexString:@"#F65757"],NSForegroundColorAttributeName,

                                      [UIFont systemFontOfSize:13.0],NSFontAttributeName,

                                      nil];

    [tabBarItem setTitleTextAttributes:noramalAtributes forState:UIControlStateNormal];

    [tabBarItem setTitleTextAttributes:selectedAtributes forState:UIControlStateSelected];

    //tabBarItem.badgeValue = @"";

    [tabBarItem setTitlePositionAdjustment:UIOffsetMake(0.0, 0.0)];

}

解决方法:设置tabBar的tintColor和unselectedItemTintColor来设置。


     // iOS 13以上

     self.tabBar.tintColor= [UIColor colorWithHexString:@"#F65757"];

     self.tabBar.unselectedItemTintColor = [UIColor darkGrayColor];

iOS13新出之后会有收不到推送的问题

因为iOS13的处理方法变了,处理方案代码如下:


//获取DeviceToken成功- (void)application:(UIApplication *)application

didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken

{

    //Xcode11打的包,iOS13获取Token有变化if([[[UIDevice currentDevice] systemVersion] floatValue] >=13) {

        if(![deviceToken isKindOfClass:[NSDataclass]]) {

            //记录获取token失败的描述return;

        }

        constunsigned *tokenBytes = (constunsigned *)[deviceToken bytes];

        NSString *strToken = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",

                              ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),

                              ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),

                              ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];

        NSLog(@"deviceToken1:%@", strToken);

        return;

    } else {

        NSString *token = [NSString

                      stringWithFormat:@"%@",deviceToken];

        token = [token stringByReplacingOccurrencesOfString:@"<"withString:@""];

        token = [token stringByReplacingOccurrencesOfString:@">"withString:@""];

        token = [token stringByReplacingOccurrencesOfString:@""withString:@""];

        NSLog(@"deviceToken2 is: %@", token);

    }

}

模式视图不能到顶部(没有设置modalPresentationStyle)

在iOS 13之前,模态视图默认都是全屏的,而在iOS13中,默认的样式变成了类iPhone上safari的分页样式。

解决办法:

只需要修改modalPresentationStyle为UIModalPresentationFullScreen。

黑夜模式

目前没有适配深夜模式,避免黑夜模式显示异常,在info.plist上添加UIUserInterfaceStyle,并且设置为Light。

使用CryptLib加密后解密失败

iOS13之前使用都正常,在iOS13加密后的外部同样的加密字符串解密时返回为nil错误的,在https://stackoverflow.com/questions/58098958/aes-encryption-cryptlib-in-ios-13-not-working找到了问题所在及解决方法。跟上面推送的问题类似。


NSString*hash=[out description];

解决方法:


#pragmamark - String Conversion-方法一

-(NSString*)hex:(NSData*)data{

  NSData*data=resultData;

  const unsigned*dataBytes=[data bytes];

  NSUInteger groupNum=data.length/4;

  NSString*result=[NSString string];

  for(int i=0;i<groupNum;i++){

    NSString*subStr=[NSString stringWithFormat:@"%08x",ntohl(dataBytes[i])];

    result=[NSString stringWithFormat:@"%@%@",result,subStr];

  }

  return result;

}

#pragmamark - String Conversion--方法二

-(NSString*)hex:(NSData*)data{

  NSMutableData*result = [NSMutableData dataWithLength:2*data.length];

  unsigned const char* src=data.bytes;

  unsigned char* dst = result.mutableBytes;

  unsigned char t0,t1;

  for (int i=0 ; i < data.length ; i++){

    t0 = src[i]>>4;

    t1=src[i]&0x0F;

    dst[i*2]=48+t0+(t0/10)*39;

    dst[i*2+1]=48+t1+(t1/10)*39;

  }

  return [[NSString alloc]initWithData:result encoding:NSASCIIStringEncoding];

}

相关文章

  • xcode11适配问题汇总

    因为之前项目中包含大量swift3.0的代码,一直使用xcode10.2没有时间升级,最近swift升级到4.0后...

  • 【解决】Xcode11 适配iOS14 beta IDFA,并发

    一、问题:解决在Xcode11适配 iOS14 的问题 解决 我们使用Xcode11没有iOS14的库, Xcod...

  • iOS11及Xcode9适配问题汇总

    iOS11及Xcode9适配问题汇总 iOS11及Xcode9适配问题汇总

  • iOS15适配

    对于iOS15适配汇总以及遇到的问题 注意:以下适配内容,必须适配的会以"必须"标出 UITableView Se...

  • iOS13适配(更新中)

    对于iOS13适配汇总以及遇到的问题注意:以下适配内容,必须适配的会以"必须"标出 1. Dark Model(必...

  • xocde11 适配 iOS13以下 的系统

    Xcode11 创建的项目默认 原来生命周期与window跑到了UIScene去管理了。 问题 :想适配iOS12...

  • 2019-09-20

    iOS 13 适配要点总结 - 简书 iOS 13 适配 ING... - 简书 Xcode11新建项目后的一些问...

  • Xcode11适配多语言 Localize按钮出现报错

    Xcode11适配添加多语言出现错误为the source control operation was cance...

  • iOS之iOS13适配总结

    前言 随便iOS开发开始更新变成Xcode11,适配iOS13变成了现在的当务之急。 新特性适配 一、新添加的Da...

  • ios13适配

    iOS13适配 1.私有KVC 在Xcode10上编译不会有问题,但是在Xcode11上编译的会崩溃。并且- (v...

网友评论

      本文标题:xcode11适配问题汇总

      本文链接:https://www.haomeiwen.com/subject/ugbrxhtx.html