edc*_*dcs 14 xcode google-maps objective-c cocoapods react-native
我正在构建一个React Native UI组件,该组件将使用Google Maps iOS SDK在React应用程序中呈现地图.这是作为静态Cocoa Touch Framework构建的,因此我可以在不同的项目中使用它.
到目前为止,这个框架并没有做太多,我只是试图让它在我尝试做任何有用的事情之前进行编译.我Podfile在Google Maps SDK中加载了一个,我运行了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
Run Code Online (Sandbox Code Playgroud)
我有GoogleMapView.h和GoogleMapView.m文件将在这个模块中做繁重的工作.现在他们并没有做太多的事情:
@import GoogleMaps;
@interface GoogleMapView: GMSMapView
@end
Run Code Online (Sandbox Code Playgroud)
-
#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
Run Code Online (Sandbox Code Playgroud)
然后我有GoogleMapViewManager.h和GoogleMapViewManager.m文件提供了React Native的桥梁.再说一次,这些现在做得不多了!:
#import "RCTViewManager.h"
@interface GoogleMapViewManager : RCTViewManager
@end
Run Code Online (Sandbox Code Playgroud)
-
#import "GoogleMapView.h"
#import "GoogleMapViewManager.h"
@implementation GoogleMapViewManager
RCT_EXPORT_MODULE()
- (UIView *)view
{
GoogleMapView *map = [[GoogleMapView alloc] init];
return map;
}
@end
Run Code Online (Sandbox Code Playgroud)
我已经将这个库添加到我的React Native XCode项目中了 - 列出了一些红色文件(我不太清楚它们是什么意思?):
我还将我的静态库中的产品添加到主React项目部分的Link Binary With Libraries列表中Build Phases:
但是,当我尝试编译项目时,我得到一些错误导致构建失败,如下所示:
我确定在使用CocoaPods导入Google Maps SDK时我做错了..xcworkspace在将我的静态库导入React应用程序时,我无法关注文档并使用该文件,这可能是错误的,但我无法弄清楚如何让它运行!
更新:
我可以得到代码编译,如果我包括使用地图项目.xcworkspace文件,但当时我不能够访问的二进制文件,或将它们任意构建阶段这是不是有用:
有谁知道我怎么能利用谷歌地图iOS版SDK的这样一个阵营原生应用程序?
如果您有一个 React Native 应用程序项目(我们将其称为 )MyApp.xcodeproj,并且您正在包含一个库项目 ,GoogleMapView.xcodeproj则您将无法仅通过将其拖入 GoogleMapView 中来使用 CocoaPods,就像MyApp.xcodeproj您在本例中所做的那样。
如果您想使用 CocoaPods 拉取 Pod GoogleMaps,则还必须GoogleMapView使用 CocoaPods 拉取您的项目。
就像这样:
# MyApp/Podfile
pod 'GoogleMapView', :path => 'Libraries/GoogleMapView'
Run Code Online (Sandbox Code Playgroud)
但在此之前,您需要确保GoogleMapView项目/私有 CocoaPod 已正确配置。
首先,Podfile:
# MyApp/Libraries/GoogleMapView/Podfile
pod 'GoogleMaps'
Run Code Online (Sandbox Code Playgroud)
然后是 Podspec。该文件将项目标记为 CocoaPods 库。
您可以使用 生成它pod spec create GoogleMapView。
这是你需要的样子:
# MyApp/Libraries/GoogleMapView/GoogleMapView.podspec
Pod::Spec.new do |s|
s.name = "GoogleMapView"
s.version = "0.0.1"
s.summary = "A short description of GoogleMapView."
s.description = <<-DESC
DESC
s.homepage = "http://EXAMPLE/GoogleMapView"
s.license = "MIT (example)"
s.author = { "David Young-Chan Kay" => "davidykay@gmail.com" }
s.source = { :git => "http://EXAMPLE/GoogleMapView.git", :tag => "0.0.1" }
s.source_files = "Classes", "Classes/**/*.{h,m}"
s.exclude_files = "Classes/Exclude"
# This is the key line. You must add it by hand.
s.dependency 'GoogleMaps'
end
Run Code Online (Sandbox Code Playgroud)
一旦这三个文件就位,您将能够重新使用您GoogleMapView正在使用的 CocoaPods!
您甚至可以将其上传到中央 CocoaPods 存储库以便与其他人共享。
希望这可以帮助。如果您需要澄清,请告诉我。
| 归档时间: |
|
| 查看次数: |
1834 次 |
| 最近记录: |