【问题标题】:Linker command failed with exit code 1 (React native - ios)链接器命令失败,退出代码为 1(React native - ios)
【发布时间】:2016-06-12 16:59:31
【问题描述】:

我正在关注iOS MapView example

我在 Project/ProjectFolder/RCTMapManager.m 中创建了一个新的 Objective-C .m 文件,并添加了以下代码:

// RCTMapManager.m
#import <MapKit/MapKit.h>

#import "RCTViewManager.h"

@interface RCTMapManager : RCTViewManager
@end

@implementation RCTMapManager

RCT_EXPORT_MODULE()

- (UIView *)view
{
  return [[MKMapView alloc] init];
}

@end

然后我打开 atom 并在 components/MapView.js 中创建了一个 js 文件并添加了以下代码:

// MapView.js

import { requireNativeComponent } from 'react-native';

// requireNativeComponent automatically resolves this to "RCTMapManager"
module.exports = requireNativeComponent('RCTMap', null);

然后在 Xcode 中运行构建命令来重建我之前工作的项目,构建失败并显示错误消息:

然后我注释掉了 MapView.js 中的所有内容,并注释掉了 RCTMapManager.m 中的实现。

这将构建:

// RCTMapManager.m
#import <MapKit/MapKit.h>

#import "RCTViewManager.h"

@interface RCTMapManager : RCTViewManager
@end

但是一旦我添加了实现,它就会失败并显示“链接器命令失败,退出代码 1”:

// RCTMapManager.m
#import <MapKit/MapKit.h>

#import "RCTViewManager.h"

@interface RCTMapManager : RCTViewManager
@end

@implementation RCTMapManager

RCT_EXPORT_MODULE()

- (UIView *)view
{
  return [[MKMapView alloc] init];
}

@end

我想知道为什么实施会导致失败,以及如何解决?

【问题讨论】:

    标签: objective-c xcode react-native


    【解决方案1】:

    RCTMapManager 已经在 react-native 中定义。我猜文档中的示例是在添加到库之前编写的。

    如果您只想使用地图,请查看MapView

    但是,如果您想试验自定义原生组件,请更改您使用的类名。在 Objective-C 中,类名通常以三个字母为前缀,描述您的公司或项目(这就是 RCT 的来源)。

    【讨论】:

      猜你喜欢
      • 2022-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-16
      • 2019-08-01
      • 2018-11-03
      相关资源
      最近更新 更多