gpt4 book ai didi

xcode - iOS 共享扩展无法与react-native 0.61.5 一起使用

转载 作者:行者123 更新时间:2023-12-02 22:19:04 25 4
gpt4 key购买 nike

我正在尝试在共享扩展(使用 XCode 添加)中使用已注册的 (AppRegistry.registerComponent) react native 模块。在早期版本的react-native中,我们只需在Build Phases > Link Binaries with Libraries中手动链接必要的库即可启动并运行。但从 v0.60 开始,这不再可能。

此问题类似于 this one但在旧版本的react-native上,其解决方案不适用于最新版本。

更多详细信息请参阅 GitHub Issue

index.share.js

import {AppRegistry} from 'react-native';
import ShareExtension from './ShareExtension';
AppRegistry.registerComponent('ShareExtension', () => ShareExtension);

ShareVIewController.m > loadView

- (void)loadView {
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:nil];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@"ShareExtension"
initialProperties:nil];
self.view = rootView;
}

这里有一个包含所有这些设置的存储库来重现此问题:GitHub Repo

Screenshot of the error

最佳答案

您已将依赖项切换到 cocoapods。检查您手动链接的 ShareExtension 包后,它会尝试引用您列出的依赖项

#import <React/RCTBridge.h>
#import <React/RCTRootView.h>

但这些实际上位于您的开发 Pod 文件夹内,基本上位于不同的范围内。

There's a number of ways to resolve this problem.

我发现解决这个问题最简单的方法就是为它创建自己的小存储库,并像任何其他依赖项一样调用它。

你可以为它创建一个 git 存储库。我按照https://github.com/react-native-community/react-native-push-notification-ios建模我的

您还可以查看以下内容了解如何调用本地 cocoapods 目录: Podfile: Path of local pod relative to Projectpath possible?

只需创建自己的 podspec 来引用 ShareExtension 中的本地文件,可能如下所示:

require "json"

package = JSON.parse(File.read(File.join(File.dirname(__FILE__), "package.json")))

Pod::Spec.new do |s|
# NPM package specification

s.name = 'Share Extension'
s.version = package['version']
s.summary = package['description']
s.description = package['description']
s.license = package['license']
s.author = package['author']
s.homepage = package['homepage']

s.source = { :git => "https://github.com/react-native-community/react-native-share-extension", :tag => "v#{s.version}" }
s.source_files = "ios/*.{h,m}"

s.platform = :ios, "9.0"

s.dependency "React"

end

关于xcode - iOS 共享扩展无法与react-native 0.61.5 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59616054/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com