我正在構建一個React本地用戶界面組件,它將利用Google Maps iOS SDK在React應用中呈現地圖。這是作爲一個靜態的Cocoa Touch框架構建的,以便我可以在不同的項目中使用它。在React Native自定義用戶界面組件中使用CocoaPods模塊
到目前爲止,這個框架並沒有太多的工作,我只是試圖在我嘗試和做任何有用的事情之前去編譯它。我有它加載在谷歌地圖SDK一個Podfile
,我已經運行pod install
命令:
# Uncomment this line to define a global platform for your project
platform :ios, '8.1'
# Uncomment this line if you're using Swift
# use_frameworks!
target 'GoogleMapView' do
source 'https://github.com/CocoaPods/Specs.git'
pod 'GoogleMaps'
end
我有GoogleMapView.h
和GoogleMapView.m
文件,這將做到這一點模塊中繁重。現在他們並不真正做太多:
@import GoogleMaps;
@interface GoogleMapView: GMSMapView
@end
-
#import "GoogleMapView.h"
@implementation GoogleMapView {
GMSMapView *mapView_;
}
- (void)viewDidLoad {
// Create a GMSCameraPosition that tells the map to display the
// coordinate -33.86,151.20 at zoom level 6.
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
longitude:151.20
zoom:6];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
self.view = mapView_;
// Creates a marker in the center of the map.
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
marker.title = @"Sydney";
marker.snippet = @"Australia";
marker.map = mapView_;
}
@end
然後,我有GoogleMapViewManager.h
和GoogleMapViewManager.m
文件,這提供了橋樑反應原住民。同樣,這些不會做太多,現在!:
#import "RCTViewManager.h"
@interface GoogleMapViewManager : RCTViewManager
@end
-
#import "GoogleMapView.h"
#import "GoogleMapViewManager.h"
@implementation GoogleMapViewManager
RCT_EXPORT_MODULE()
- (UIView *)view
{
GoogleMapView *map = [[GoogleMapView alloc] init];
return map;
}
@end
我已經添加了這個庫,以我的母語做出反應的XCode項目,像這樣 - 有列出了一些紅色的文件(我也不太清楚他們的意思):
我還添加了產品從我的靜態庫的Link Binary With Libraries
列表中主要陣營項目部分:
然而,當我嘗試編譯項目時,我得到了一些錯誤,這是導致構建失敗,像這樣:
我確定我在使用CocoaPods導入Google Maps SDK時做了一些錯誤。當我將靜態庫導入React應用程序時,我無法關注文檔並使用.xcworkspace
文件,這可能是什麼問題,但我無法弄清楚如何讓它運行!
更新:
我可以得到代碼編譯,如果我包括使用.xcworkspace
文件地圖項目,但當時我不能夠訪問的二進制文件,或將它們任意構建階段,其ISN 「T有用:
有誰知道我怎麼能利用谷歌地圖iOS版SDK的這樣一個陣營原生應用程序?
不知道如何在庫項目中使用CocoaPods,但可以直接在您的原始React項目中包含那些與Google地圖相關的類(如果您不打算共享該庫) –
這就是我不得不恢復到這樣做 - 如果您需要更新React版本,則會導致嚴重的問題,因爲#react-native upgrade命令會使XCode項目變得混亂。 – edcs
我認爲最簡單的方法是通過CocoaPods安裝react-native並將你的依賴添加爲另一個Pod。 – Adamski