OC项目创建iOS 14 Widget 时编译报错

起因

最近产品要做一个Widget小组件,产品的要求必须安排。于是我新创建了一个OC项目,然后创建了一个Widget Extension。直接运行编译,发编译器报以下错误: ld: Assertion failed: (reconstituted == (accumulator - _options.machHeaderVmAddr())), function setFixup64, file OutputFile.cpp, line 2864.

ld: Assertion failed: (reconstituted == (accumulator - _options.machHeaderVmAddr())), function setFixup64, file OutputFile.cpp, line 2864.
复制代码

解决过程

查找资料在官方论坛发现了同样错误,但是没有给出解决方案。 后面通过修改了项目的Projet 支持的最低版本由iOS 15 改为 iOS14可以编译通过。 在这里插入图片描述 解决了这个错误之后,发现编译还是有其他错误。 编译报错提示: 1、Type 'Provider' does not conform to protocol 'IntentTimelineProvider' 2、Cannot find 'ConfigurationIntent' in scope

Type 'Provider' does not conform to protocol 'IntentTimelineProvider'
复制代码
Cannot find 'ConfigurationIntent' in scope
复制代码

在这里插入图片描述 查找资料才知道原因是: 我们在工程中设置了Class Prefix,我的项目设置的是CN在这里插入图片描述

导致Xcode自动生成的是CNConfigurationIntent.swift,该文件路径是:

/Users/用户名/Library/Developer/Xcode/DerivedData/项目名称/Build/Intermediates.noindex/项目名称.build/Debug-iphonesimulator/widget的名称Extension.build/DerivedSources/IntentDefinitionGenerated/widget的名称/CNConfigurationIntent.swift
复制代码

在这里插入图片描述 在这里插入图片描述

在这里插入图片描述 但是自动生成的代码又是ConfigurationIntent,只需要把代码中的ConfigurationIntent都改为工程前缀+ConfigurationIntent(CNConfigurationIntent)就可以正常运行了。 在这里插入图片描述

因为项目主工程是OC,我们在Widget中创建了两个OC文件与桥接文件CNHotWidget-Bridging-Header后,编译发现又开始报错。

Type 'Provider' does not conform to protocol 'IntentTimelineProvider'
Cannot find 'CNConfigurationIntent' in scope
复制代码

在这里插入图片描述 解决这个问题,需要我们在桥接文件CNHotWidget-Bridging-Header中引入#import "CNConfigurationIntent.h"

在这里插入图片描述

Supongo que te gusta

Origin juejin.im/post/7071436772898504712
Recomendado
Clasificación