Xamarin的坑 - 绑定(二) - 高德iOS SDK(.Framework)绑定的一些事
編者語:入門總是用一個hello world,總會讓人覺得寫code會是很容易的事。開篇綁定了一下微信SDK,不會有太多的難點,可是接下來的這個例子如果欠缺一些耐心,估計你整個人就崩潰了(我從來不會放棄任何的事)。ps這里得謝謝CSDN回帖的人,提示我把一些概念搞錯了。嗯!我會修正回來。?我直接拿名家@onevat的日志重新把靜態(tài)庫(.a)和動態(tài)框架(Framework)的概念重新引用一次,哈哈希望不會有任何理解上的.
? ? ? ?
? ? ? ?了解更多可以看?https://onevcat.com/2016/01/create-framework/
? ? ? ?第三庫在iOS 8后更多用Framework進行封裝。本篇以高德SDK為例去完成一個Xamarin對Framework綁定的示例, 我樂意為大家填坑。
? ? ? ?高德地圖iOS SDK?http://lbs.amap.com/api/ios-sdk/summary?
? ? ? ?我在這里主要用3D地圖,主要涉及兩個Framework AMapFoundationKit.framework(這是高德的基礎(chǔ)庫任意地方都需要使用) 和 MAMapKit.framework(3D地圖庫) 。
? ? ? ?
? ? ? ?1. 在命令行下通過sharpie把兩個framework進行分別轉(zhuǎn)換
? ? ? ? ? ?AMapFoundationKit轉(zhuǎn)換
sharpie?bind?-framework?/your?path/AMapFoundationKit.framework?-sdk?iphoneos10.2??
? ? ? ? ? ?MAMapKit轉(zhuǎn)換
sharpie?bind?-framework?/your?path/MAMapKit.framework?-sdk?iphoneos10.2??
? ? ? ?2. 分別創(chuàng)建對應(yīng)于AMapFoundationKit和MAMapKit?Binding項目,并把生成文件嵌入對應(yīng)項目中(你可以參照本系列一進行操作http://blog.csdn.net/u014388424/article/details/55517845),還有把Framework放進Binding項目中的Native References文件夾中。
? ? ? ?
? ? ? 2. 首先嘗試編譯AMap.iOS Binding ,估計都不會成功的啦,這是常識吧!
? ? ??
? ? ? 看看錯誤在Structs
? ? ??
? ? ? 是類型錯,一般nint需要轉(zhuǎn)換為C#的類型,我這里把它轉(zhuǎn)換成ulong就基本上完事了。 再編譯會提示Verify的問題了,把它注釋掉。再重新編譯就可以順利把AMapFoundationKit的Binding解決了。(這個和WeChat SDK差不多)。還有別忘記加入using CoreLocation 因為?CLLocationCoordinate2D 需要用到的。
? ?轉(zhuǎn)換時的命名錯誤也是需要修改
? ?
? ? ?修正后為
? ? ?
<span?style="font-size:14px;">public?enum?MAOfflineCityStatus?:?uint??
{??
????None?=?MAOfflineItemStatus.None,??
????Cached?=?MAOfflineItemStatus.Cached,??
????Installed?=?MAOfflineItemStatus.Installed,??
????Expired?=?MAOfflineItemStatus.Expired??
}</span>??
?
? ? ?2. 入坑后,再編譯AMap.iOS.3D Binding估計你就會哭了,別怕哥幫你刷眼淚。不過這也是一個很好的長經(jīng)驗例子。
? ? ??
? ? ? 初始錯誤分幾種
? ? ? a. Structs.cs類型錯,這種和第一步一樣修正為long
? ? ???
? ? ? b.ApiDefinition.cs?[Verify(ConstantsInterfaceAssociation)]
? ? ? ? ?這里得說明一下,除了注釋這個字段外,還需要合并多個partial?interface?Constants為一個Constants。
partial?interface?Constants??
????{??
????????//?extern?NSString?*const?AMapFoundationVersion;??
????????[Field("AMapFoundationVersion",?"__Internal")]??
????????NSString?AMapFoundationVersion?{?get;?}??
??
????????//?extern?NSString?*const?AMapFoundationName;??
????????[Field("AMapFoundationName",?"__Internal")]??
????????NSString?AMapFoundationName?{?get;?}??
??
????????//?extern?NSString?*const?MAMapKitVersion;??
????????[Field("MAMapKitVersion",?"__Internal")]??
????????NSString?MAMapKitVersion?{?get;?}??
??
????????//?extern?NSString?*const?MAMapKitName;??
????????[Field("MAMapKitName",?"__Internal")]??
????????NSString?MAMapKitName?{?get;?}??
????????//?extern?const?MAMapSize?MAMapSizeWorld;??
????????[Field("MAMapSizeWorld",?"__Internal")]??
????????MAMapSize?MAMapSizeWorld?{?get;?}??
??
????????//?extern?const?MAMapRect?MAMapRectWorld;??
????????[Field("MAMapRectWorld",?"__Internal")]??
????????MAMapRect?MAMapRectWorld?{?get;?}??
??
????????//?extern?const?MAMapRect?MAMapRectNull;??
????????[Field("MAMapRectNull",?"__Internal")]??
????????MAMapRect?MAMapRectNull?{?get;?}??
??
????????//?extern?const?MAMapRect?MAMapRectZero;??
????????[Field("MAMapRectZero",?"__Internal")]??
????????MAMapRect?MAMapRectZero?{?get;?}??
??
????????//?extern?NSString?*const?kMAMapLayerCenterMapPointKey;??
????????[Field("kMAMapLayerCenterMapPointKey",?"__Internal")]??
????????NSString?kMAMapLayerCenterMapPointKey?{?get;?}??
??
????????//?extern?NSString?*const?kMAMapLayerZoomLevelKey;??
????????[Field("kMAMapLayerZoomLevelKey",?"__Internal")]??
????????NSString?kMAMapLayerZoomLevelKey?{?get;?}??
??
????????//?extern?NSString?*const?kMAMapLayerRotationDegreeKey;??
????????[Field("kMAMapLayerRotationDegreeKey",?"__Internal")]??
????????NSString?kMAMapLayerRotationDegreeKey?{?get;?}??
??
????????//?extern?NSString?*const?kMAMapLayerCameraDegreeKey;??
????????[Field("kMAMapLayerCameraDegreeKey",?"__Internal")]??
????????NSString?kMAMapLayerCameraDegreeKey?{?get;?}??
??
????????[Field("MAOfflineMapDownloadReceivedSizeKey",?"__Internal")]??
????????NSString?MAOfflineMapDownloadReceivedSizeKey?{?get;?}??
??
????????//?extern?NSString?*const?MAOfflineMapDownloadExpectedSizeKey;??
????????[Field("MAOfflineMapDownloadExpectedSizeKey",?"__Internal")]??
????????NSString?MAOfflineMapDownloadExpectedSizeKey?{?get;?}??
????????[Field("MAOfflineMapErrorDomain",?"__Internal")]??
????????NSString?MAOfflineMapErrorDomain?{?get;?}??
????}??
? ? ? ? 這里有一些接口的錯誤
? ? ? ??
? ? ? ? 修改為:
? ? ? ??
? ? ? ? 需要修正命名錯誤,用sharpie轉(zhuǎn)換很容易把不同方法轉(zhuǎn)換成同個名字
? ? ? ??
? ? ? ? 還有把Objective-C的指針*作為變量加上去了(這個也夠搞笑,希望Sharpie下個版本能修正),都要刪除掉*就解決了 ?
//?-(void)renderLinesWithPoints:(CGPoint?*)points?pointCount:(NSUInteger)pointCount?strokeColor:(UIColor?*)strokeColor?lineWidth:(CGFloat)lineWidth?looped:(BOOL)looped?LineJoinType:(MALineJoinType)lineJoinType?LineCapType:(MALineCapType)lineCapType?lineDash:(BOOL)lineDash;??
[Export("renderLinesWithPoints:pointCount:strokeColor:lineWidth:looped:LineJoinType:LineCapType:lineDash:")]??
unsafe?void?RenderLinesWithPoints(CGPoint*?points,?nuint?pointCount,?UIColor?strokeColor,?nfloat?lineWidth,?bool?looped,?MALineJoinType?lineJoinType,?MALineCapType?lineCapType,?bool?lineDash);??
? ? ? ? ?還是Verify字段要去掉
? ? ? ??
? ? ? ?這里有一個更好玩的事,就是擴展方法這里轉(zhuǎn)換老提示以下錯誤
? ? ? ?
? ? ? ?我查看了一下,發(fā)現(xiàn)是怎么也不認(rèn)擴展方法,看了看stackoverflow ,發(fā)現(xiàn)需要把每個屬性的get/set通過方法描述解決,這也是醉了。。。。。如這個
[Export("allowsAnnotationViewSorting")]??
bool?AllowsAnnotationViewSorting?{?get;?set;?}??
? ? ? ?需要修正為:
[Export("allowsAnnotationViewSorting")]??
//bool?AllowsAnnotationViewSorting?{?get;?set;?}??
bool?AllowsAnnotationViewSorting();??
[Export("setAllowsAnnotationViewSorting:")]??
void?SetAllowsAnnotationViewSorting(bool?allowsAnnotationViewSorting);???
? ? ? 按照上述步驟基本上就可以把項目編譯成功了。? ? ? ???
? ? ??
? ? ? 3.接下來就是添加一個iOS項目,做一個簡單測試。
? ? ? 這里需要補充一下,需要對MAMapKit.framework補充關(guān)聯(lián)
? ? ? ??
? ? ? ? 在Info.plist中 Location Always Usage Description
? ? ? ??? ? ? ?
? ? ? ? 還需要把兩個綁定Binding引用進去
? ? ? ??
? ? ? ? 還需要把AMap資源引用去Resource目錄(bundle在MAMapKit.framework內(nèi))
? ? ? ??
? ? ? ? 最后只需要在ViewController.cs添加如下代碼就可以了
AMapServices.SharedServices.ApiKey?=?"你申請的key";??
AMapServices.SharedServices.EnableHTTPS?=?true;??
MAMapView?map?=?new?MAMapView();??
map.Frame?=?this.View.Bounds;??
map.SetShowsUserLocation(true);??
map.SetUserTrackingMode(MAUserTrackingMode.Follow);??
this.View.AddSubview(map);??
? ? ? ?Rebuild一下運行
? ? ? ?? ?
? ? ? 爽爽!!
? ? ? 代碼在github上?https://github.com/lokinfey/AMapSDK,由于時間有限我只會暫時先放一個簡單的定位功能上去。給有緣人自己添加功能了。
相關(guān)文章:
- Xamarin的坑 - 綁定(一) - 拿微信iOS SDK 簡單說起 
原文地址:http://blog.csdn.net/kinfey/article/details/56303998
.NET社區(qū)新聞,深度好文,微信中搜索dotNET跨平臺或掃描二維碼關(guān)注
贊賞
人贊賞
總結(jié)
以上是生活随笔為你收集整理的Xamarin的坑 - 绑定(二) - 高德iOS SDK(.Framework)绑定的一些事的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 分布式事务与一致性算法Paxos amp
- 下一篇: 如何使Mac Docker支持SQL o
