【问题标题】:Use of undeclared identifier 'AIRGoogleMapOverlay' in AIRGoogleMapOverlayManager even after #import "AIRGoogleMapOverlay.h"即使在#import "AIRGoogleMapOverlay.h" 之后在 AIRGoogleMapOverlayManager 中使用未声明的标识符 'AIRGoogleMapOverlay'
【发布时间】:2018-11-06 15:34:32
【问题描述】:

当我尝试通过 Xcode 运行我的 react 本机项目时,我收到 Use of undeclared identifier 'AIRGoogleMapOverlay' 错误。我实际上是在尝试在我的 iPhone 上打开该应用程序,而这正是我遇到此错误的时候。如果我简单地说 react-native run-ios,它会在模拟器上构建并启动应用程序。我正在尝试提取使用模拟器无法完成的当前设备位置。

该错误发生在 react-native-google-maps 包中的 AirGoogleMapOverlayManager.m 文件中。

AIRGoogleMapOverlay.h

#ifdef HAVE_GOOGLE_MAPS

#import <Foundation/Foundation.h>
#import <GoogleMaps/GoogleMaps.h>
#import <React/RCTBridge.h>
#import "AIRMapCoordinate.h"
#import "AIRGoogleMap.h"

@interface AIRGoogleMapOverlay : UIView

@property (nonatomic, strong) GMSGroundOverlay *overlay;
@property (nonatomic, copy) NSString *imageSrc;
@property (nonatomic, strong, readonly) UIImage *overlayImage;
@property (nonatomic, copy) NSArray *boundsRect;
@property (nonatomic, readonly) GMSCoordinateBounds *overlayBounds;

@property (nonatomic, weak) RCTBridge *bridge;

@end

#endif

AIRGoogleMapOverlay.m

#ifdef HAVE_GOOGLE_MAPS

#import "AIRGoogleMapOverlay.h"

#import <React/RCTEventDispatcher.h>
#import <React/RCTImageLoader.h>
#import <React/RCTUtils.h>
#import <React/UIView+React.h>

@interface AIRGoogleMapOverlay()
  @property (nonatomic, strong, readwrite) UIImage *overlayImage;
  @property (nonatomic, readwrite) GMSCoordinateBounds *overlayBounds;
@end

@implementation AIRGoogleMapOverlay {
  RCTImageLoaderCancellationBlock _reloadImageCancellationBlock;
  CLLocationCoordinate2D _southWest;
  CLLocationCoordinate2D _northEast;
}

- (instancetype)init
{
  if ((self = [super init])) {
    _overlay = [[GMSGroundOverlay alloc] init];
  }
  return self;
}

- (void)setImageSrc:(NSString *)imageSrc
{
  NSLog(@">>> SET IMAGESRC: %@", imageSrc);
  _imageSrc = imageSrc;

  if (_reloadImageCancellationBlock) {
    _reloadImageCancellationBlock();
    _reloadImageCancellationBlock = nil;
  }

  __weak typeof(self) weakSelf = self;
  _reloadImageCancellationBlock = [_bridge.imageLoader loadImageWithURLRequest:[RCTConvert NSURLRequest:_imageSrc]
                                                                          size:weakSelf.bounds.size
                                                                         scale:RCTScreenScale()
                                                                       clipped:YES
                                                                    resizeMode:RCTResizeModeCenter
                                                                 progressBlock:nil
                                                              partialLoadBlock:nil
                                                               completionBlock:^(NSError *error, UIImage *image) {
                                                                 if (error) {
                                                                   NSLog(@"%@", error);
                                                                 }
                                                                 dispatch_async(dispatch_get_main_queue(), ^{
                                                                   NSLog(@">>> IMAGE: %@", image);
                                                                   weakSelf.overlayImage = image;
                                                                   weakSelf.overlay.icon = image;
                                                                 });
                                                               }];

}

- (void)setBoundsRect:(NSArray *)boundsRect
{
  _boundsRect = boundsRect;

  _southWest = CLLocationCoordinate2DMake([boundsRect[1][0] doubleValue], [boundsRect[0][1] doubleValue]);
  _northEast = CLLocationCoordinate2DMake([boundsRect[0][0] doubleValue], [boundsRect[1][1] doubleValue]);

  _overlayBounds = [[GMSCoordinateBounds alloc] initWithCoordinate:_southWest
                                                        coordinate:_northEast];

  _overlay.bounds = _overlayBounds;
}

@end

#endif

这是我在 AIRGoogleMapOverlayManager 中得到错误的地方

#import "AIRGoogleMapOverlayManager.h"
#import "AIRGoogleMapOverlay.h"

@interface AIRGoogleMapOverlayManager()

@end

@implementation AIRGoogleMapOverlayManager

- (UIView *)view
{
  AIRGoogleMapOverlay *overlay = [AIRGoogleMapOverlay new]; ERROR-Use of  undeclared identifier 'AIRGoogleMApOverlay'
  overlay.bridge = self.bridge; ERROR-Use of  undeclared identifier 'overlay'
  return overlay; ERROR-Use of  undeclared identifier 'overlay'
  return 0;
}

RCT_EXPORT_MODULE()

RCT_REMAP_VIEW_PROPERTY(bounds, boundsRect, NSArray)
RCT_REMAP_VIEW_PROPERTY(image, imageSrc, NSString)

@end

我知道解决第一个错误将消除所有 3 个错误。我也在运行 xcworkspace,而不是 xcodeproj。

感谢任何帮助!

【问题讨论】:

    标签: ios xcode google-maps react-native undeclared-identifier


    【解决方案1】:

    我在预处理器宏中添加了HAVE_GOOGLE_MAPS=1,所有与 AIRGoogleMapOverlay 相关的错误都消失了。

    这需要为 DebugRelease 添加,以防有人想知道为什么他们在尝试创建离线包时遇到此错误。

    【讨论】:

    • 谢谢!我为调试而不是发布设置了我的设置。像魅力一样工作
    【解决方案2】:

    您可能需要一个桥接头。

    在您的项目中创建一个文件,例如命名为 AIRGoogleMapOverlay-Bridging-Header.h

    然后放

    #import "AIRGoogleMapOverlay.h"
    

    在里面。

    最后,根据您需要设置的环境,在您的构建设置中添加头文件,如下所示。

    【讨论】:

    • @Diphase 我也做了同样的事情。但得到以下错误。在 Pods->Development Pods-> react-native-maps ->AirGoogleMapPolyline.h 中找不到 AirMapCoordinate.h,
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多