0

I'm following along with the iOS MapView example.

I created a new Objective-C .m file in Project/ProjectFolder/RCTMapManager.m, and added the following code:

// 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

I then opened up atom and created a js file in components/MapView.js and added the following code:

// MapView.js

import { requireNativeComponent } from 'react-native';

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

And ran the build command in Xcode to rebuild my previously working project, and the build failed with the error message:

enter image description here

So I then commented out everything in MapView.js, and commented out the implementation in RCTMapManager.m.

This will build:

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

#import "RCTViewManager.h"

@interface RCTMapManager : RCTViewManager
@end

But as soon as I add the implementation, it fails with "Linker command failed with exit code 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

I wondering why the implementation is causing this to fail, and how to fix it?

1 Answer 1

1

RCTMapManager is already defined in react-native. I guess the example in the docs has been written before it was added to the library.

If you just want to use maps, have a look at MapView.

However if you want to experiment with custom native components, change the class names you use. In Objective-C class names are traditionally prefixed with three letters that describe your company or project (this is where the RCT comes from).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.