iOS15适配问题:viewForSupplementaryElementOfKind表头和表尾复用闪退,UITableView section header多22像素等问题

1.广告权限提示,需要在viewDidLoad调用授权,不然弹不出来。
Guideline 2.1 - Information Needed

We’re looking forward to completing our review, but we need more information to continue. Your app uses the AppTrackingTransparency framework, but we are unable to locate the App Tracking Transparency permission request when reviewed on iOS 15.0.1.

Since you indicated in App Store Connect that you collect data in order to track the user, we need to confirm that App Tracking Transparency has been correctly implemented.

Next Steps

Please explain where we can find the App Tracking Transparency permission request in your app. The request should appear before any data is collected that could be used to track the user.

If your app does not track users, please update your app privacy information in App Store Connect. You must have the Account Holder or Admin role to update app privacy information.

If you’ve implemented App Tracking Transparency but the permission request is not appearing on devices running the latest OS, please review the available documentation and confirm App Tracking Transparency has been correctly implemented.

Resources

  • Tracking is linking data collected from your app with third-party data for advertising purposes, or sharing the collected data with a data broker. Learn more about tracking.
  • See Frequently Asked Questions about the new requirements for apps that track users.
  • Review developer documentation for App Tracking Transparency.
    if (@available(iOS 15, *)) {
    [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
    }];
    }
    这个新加的 到viewDidLoad里面去调用
    2.后台持续定位就是不使用定位时第一安装也弹出定位授权提示框。
    指南 2.5.4 - 性能 - 软件要求

您的应用在 Info.plist 文件的 UIBackgroundModes 键中声明支持位置,但没有任何需要持久位置的功能。在 Info.plist 文件的 UIBackgroundModes 键中声明支持位置的应用程序必须具有需要持久位置的功能。

后续步骤

要解决此问题,请修改您的应用以包含需要在应用处于后台时持续使用实时位置更新的功能。

如果您的应用不需要持续实时位置更新,请从 UIBackgroundModes 键中删除“位置”设置。如果您的应用功能不需要持续实时位置更新,您可能希望使用显着变化位置服务或区域监控位置服务。

资源

有关更多信息,请查看启动显着变化位置服务和监控地理区域。
解决方案:去除持续定位配置只保留使用期间定位或增加后台持续定位的页面。
3.UICollectionReusableView不注册UICollectionElementKindSectionFooter,foot复用UICollectionElementKindSectionHeader闪退。

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0 && [kind isEqualToString:UICollectionElementKindSectionHeader])
    {
        if (self.collectionHeadView)
        {
            return self.collectionHeadView;
        }

        UICollectionReusableView *headView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader
                                                                                withReuseIdentifier:@"collectionHeadView" forIndexPath:indexPath];
        self.collectionHeadView = headView;
//        UIView *footViewPanel = [[UIView alloc] initWithFrame:CGRectMake(0, 0, FULL_WIDTH, 105)];
//        footViewPanel.backgroundColor = [UIColor clearColor];
        [headView addSubview:self.selectTypeHeadView];
        return headView;
    }
    else
    {
        if (self.lineFootView)
        {
            return self.lineFootView;
        }

        UICollectionReusableView *lineFootView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader
                                                                                withReuseIdentifier:@"lineFootView" forIndexPath:indexPath];
        self.lineFootView = lineFootView;
        UIView *lineFootViewPanel = [[UIView alloc] initWithFrame:CGRectMake(0, 0, FULL_WIDTH, BG_1PX)];
        lineFootViewPanel.backgroundColor = [UIColor clearColor];
        [lineFootView addSubview:lineFootViewPanel];
        return lineFootView;
    }
}

解决方案注册UICollectionElementKindSectionFooter,使用正确的UICollectionElementKindSectionFooter。

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0 && [kind isEqualToString:UICollectionElementKindSectionHeader])
    {
        if (self.collectionHeadView)
        {
            return self.collectionHeadView;
        }

        UICollectionReusableView *headView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader
                                                                                withReuseIdentifier:@"collectionHeadView" forIndexPath:indexPath];
        self.collectionHeadView = headView;
//        UIView *footViewPanel = [[UIView alloc] initWithFrame:CGRectMake(0, 0, FULL_WIDTH, 105)];
//        footViewPanel.backgroundColor = [UIColor clearColor];
        [headView addSubview:self.selectTypeHeadView];
        return headView;
    }
    else
    {
        if (self.lineFootView)
        {
            return self.lineFootView;
        }

        UICollectionReusableView *lineFootView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter
                                                                                withReuseIdentifier:@"lineFootView" forIndexPath:indexPath];
        self.lineFootView = lineFootView;
        UIView *lineFootViewPanel = [[UIView alloc] initWithFrame:CGRectMake(0, 0, FULL_WIDTH, BG_1PX)];
        lineFootViewPanel.backgroundColor = [UIColor clearColor];
        [lineFootView addSubview:lineFootViewPanel];
        return lineFootView;
    }
}
[_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"lineFootView"];

闪退日志:

2021-11-11 13:40:13.711962+0800 光予露家长端[55011:3110902] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'the view returned from -collectionView:viewForSupplementaryElementOfKind:atIndexPath: does not match the element kind it is being used for. When asked for a view of element kind 'UICollectionElementKindSectionFooter' the data source dequeued a view registered for the element kind 'UICollectionElementKindSectionHeader'.'
*** First throw call stack:
(0x181d5b05c 0x19a275f54 0x18361c99c 0x184326c6c 0x184393844 0x1842e73c4 0x1842f9c6c 0x185a53280 0x185a45aa8 0x185a5a0b0 0x185a63174 0x184308d90 0x1842d8940 0x1842ddc68 0x181d7d030 0x181d8dcf0 0x181cc7ff8 0x181ccd804 0x181ce13c8 0x19d4f238c 0x184687060 0x184404b8c 0x10544d8d0 0x106699a24)
libc++abi: terminating with uncaught exception of type NSException
dyld4 config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'the view returned from -collectionView:viewForSupplementaryElementOfKind:atIndexPath: does not match the element kind it is being used for. When asked for a view of element kind 'UICollectionElementKindSectionFooter' the data source dequeued a view registered for the element kind 'UICollectionElementKindSectionHeader'.'
terminating with uncaught exception of type NSException

5.UIView不生成对象设置颜色闪退。

有问题的代码:

- (instancetype)initWithFrame:(CGRect)frame underlineColor:(UIColor *)underlineColor TitleArr:(NSMutableArray *)titleArr textColor:(UIColor *)textColor selectTextColor:(UIColor *)selectTextColor
{
    self.backgroundColor = [UIColor clearColor];
    self = [super initWithFrame:frame];
    if (self)
    {
        [self initSubPanelWithTitleArr:titleArr underlineColor:underlineColor textColor:textColor selectTextColor:selectTextColor];
    }
    return self;
}

修改后的代码:

- (instancetype)initWithFrame:(CGRect)frame underlineColor:(UIColor *)underlineColor TitleArr:(NSMutableArray *)titleArr textColor:(UIColor *)textColor selectTextColor:(UIColor *)selectTextColor
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self initSubPanelWithTitleArr:titleArr underlineColor:underlineColor textColor:textColor selectTextColor:selectTextColor];
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}

闪退日志:

2021-11-11 13:36:59.511303+0800 光予露家长端[54977:3108685] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UIView is missing its initial trait collection populated during initialization. This is a serious bug, likely caused by accessing properties or methods on the view before calling a UIView initializer. View: <BGCommonScrollToolPanel: 0x1070592e0; frame = (0 0; 0 0); transform = [0, 0, 0, 0, 0, 0]; anchorPoint = (0, 0); alpha = 0; opaque = NO; layer = (null)>'
*** First throw call stack:
(0x181d5b05c 0x19a275f54 0x18361cb04 0x1853fbf54 0x1842d35f0 0x1845fca9c 0x10545b95c 0x105336b44 0x18431fbdc 0x185227b30 0x1842e0008 0x18457f814 0x1844c5608 0x18441b334 0x1842e963c 0x1842f9c6c 0x185a53280 0x185a45aa8 0x185a5a0b0 0x185a63174 0x185a45210 0x181d03570 0x181cd2854 0x181ccd8ec 0x181ce13c8 0x19d4f238c 0x184687060 0x184404b8c 0x1053518d0 0x106655a24)
libc++abi: terminating with uncaught exception of type NSException
dyld4 config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UIView is missing its initial trait collection populated during initialization. This is a serious bug, likely caused by accessing properties or methods on the view before calling a UIView initializer. View: <BGCommonScrollToolPanel: 0x1070592e0; frame = (0 0; 0 0); transform = [0, 0, 0, 0, 0, 0]; anchorPoint = (0, 0); alpha = 0; opaque = NO; layer = (null)>'

6.iOS 15 的 UITableView section header多22像素问题
iOS 15 的 UITableView又新增了一个新属性:sectionHeaderTopPadding 会给每一个section header 增加一个默认高度,当我们 使用 UITableViewStylePlain 初始化 UITableView的时候,就会发现,系统给section header增高了22像素。
解决办法:

if (@available(iOS 15.0, *)) {
    tableView.sectionHeaderTopPadding = 0;
}

7.The file “xxx.entitlements” could not be opened. Verify the value of the CODE_SIGN_ENTITLEMENTS build setting for target “xxxxxx” and build configuration “debug” is correct and that the file exists on disk. (in target “xxxxxx”)

解决方法:
1、百度很多教程都是说证书配合问题,只需要在capability中的推送开关, 关闭然后在打开就好了;

但是我遇到的问题中,修改了项目名和类名后,在capability中的推送的扩展Push Notifications不见了,在点击 +Capability 按钮去添加Push Notifications模块时,居然双击添加后,居然添加不上,不知道是不是Xcode(version - 11.3.1)的问题,最终自己通过下面的方法解决问题。

2、打开项目,选择target中对应的项目target, 选择 Build Setting,在搜索中输入 enti 简写,然后找到 Signing 下的 Code Signing Entitlements 中的xxx/xxx.entitlements 修改成你app的名称,如:xxx/app名称.entitlements, 重新编译就可以了;或者你直接删掉 Signing 下的 Code Signing Entitlements 中的xxx/xxx.entitlements,然后重新编译也可以。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值