Xamarin在其官方博客上宣布三个跨平台组件:Xamarin.Mobile、Xamarin.Social和Xamarin.Auth更新而且开源。html
这些组件也能够在Xamarin组件商店下载,提供如下功能:git
查看每一个组件更多详细信息: Xamarin.Mobile, Xamarin.Auth和Xamarin.Social.github
为了演示使用这3个组件建立Apps是如此简单,提供了一个简单App(SoMA)示例。该App实现拍照而后分享到社交媒体,同时使用Google地图来标记位置的功能。示例程序综合应用了三个组件:使用Xamarin.Mobile访问照相机和地址位置服务(location services);使用Xamarin.Social(结合Xamarin.Auth)集成Facebook、Twitter、Flickr、App.net……全部这些只经过几十行代码实现。示例源码可从github下载。
安全
这是部分截图,提供一个自定义的数据输入表单。网络
下面这段代码,能够工做在Xamarin.iOS、Xamarin.Adnroid、Window Phone和Windows 8this
var locator = new Geolocator { DesiredAccuracy = 50 }; // new Geolocator (this) { ... }; on Android var position = await locator.GetPositionAsync (timeout: 10000); Console.WriteLine ("Position Latitude: {0}", position.Latitude); Console.WriteLine ("Position Longitude: {0}", position.Longitude); location = string.Format("{0},{1}", position.Latitude, position.Longitude); LocationText.Text = location; // on UI
使用Xamarin.Socail将图片发送到Facebook获取其余社交网络变得简单,下面的代码片断能够在iOS和Android运行:编码
// 1. Create the service var facebook = new FacebookService { ClientId = "YOUR_CLIENT_ID", RedirectUrl = new System.Uri ("http://www.facebook.com/connect/login_success.html") }; // 2. Create an item to share var item = new Item { Text = "Xamarin.Social rocks!" }; item.Images.Add(new ImageData(fileName)); // 3. Present the UI on Android var shareIntent = service.GetShareUI (this, item, result => { // result lets you know if the user shared the item or canceled Console.WriteLine(service.Title + " shared"); }); StartActivity (shareIntent); // 3. Present the UI on iOS var shareController = facebook.GetShareUI (item, result => { // result lets you know if the user shared the item or canceled DismissViewController (true, null); }); PresentViewController (shareController, true, null);
更重要的是:spa
全部这些组件开源,能够在github上查看代码:Xamarin.Social, Xamarin.Mobile and Xamarin.Auth。
.net
相信对于移动跨平台开发者来讲,这是一个很是棒的新闻,有两个缘由:第一,你能够看到咱们如何经过跨平台的方式封装特定平台的特性(如地理位置);第二,由于开源,你能够扩展类库以支持新的硬件特性或社交媒体。code
但愿你喜欢使用这些组件和在编码中探索新的乐趣!
相关阅读: