MonoTouch:使用可移植类库创建多平台应用程序 [英] MonoTouch: creating multiplatform apps using Portable Class Libraries

查看:82
本文介绍了MonoTouch:使用可移植类库创建多平台应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的情况:尝试将我们公司创建的应用程序的一小部分从本机代码(iOS的ObjC/安卓的Java)移植到C-Sharp.该项目将与我们的Web服务进行交互.该项目的目标是弄清楚将整个应用程序移植到Mono的可行性.

My scenario: trying to port a small part of an application created by our company from native code (ObjC for iOS / Java for Android) to C-Sharp. The project will interact with our webservices. Goal of this project is figuring out how feasible it is to port our whole app to Mono.

要创建URL,我想使用String.Format().我认为将这个服务层"放在可移植类库(PCL)中是一个明智的主意,因为我不希望这段代码在各个平台上都可以更改.可悲的是,似乎String库不适用于PCL.

To create URLs, I'd like to use String.Format(). I thought it'd be a wise idea to put this 'service layer' inside a Portable Class Library (PCL) since I don't expect this code to change across platforms. Sadly, it seems the String library is not available for PCLs.

所以我的问题如下:

  1. 我认为PCL相对于普通"库的主要优势在于,它们不需要针对不同平台进行重新编译.这个假设正确吗?
  2. 这种经历使我认为,目前PCL相当有限.我应该尝试坚持使用PCL并解决这些问题,还是暂时坚持使用常规"库会更好? ---我假设常规"库具有更多功能.

推荐答案

您目前可以在许多平台上使用PCL,但确实需要一些小技巧来进行设置.

You can use PCLs currently across many platforms, but it does require some small hacks to your setup.

http://slodge.blogspot.co中列出了这些黑客. uk/2012/12/cross-platform-winrt-monodroid.html

一旦这些都可以使用,那么可用的功能就非常广泛-它肯定包括String.Format之类的东西

Once you've got those working then the functionality available is quite broad - and it definitely includes things like String.Format

对于PCL配置文件不够广泛的情况,则可以使用多种技术来扩展它们-请参见http://blogs.msdn.com/b/dsplaisted/archive/2012/08/27/how-to- make-portable-class-libraries-for-you.aspx .我通常使用的技术是使用MvvmCross插件-基本上是具有平台特定实现的PCL接口. 但是,这些插件通常处于使蓝牙起作用"的级别,而不是String.Format的级别

For the situations where the PCL profile is not broad enough, then you can use several techniques for extending them - see http://blogs.msdn.com/b/dsplaisted/archive/2012/08/27/how-to-make-portable-class-libraries-work-for-you.aspx . The technique I generally use is to use MvvmCross Plugins - which are basically PCL interfaces with platform specific implementations. But these plugins are generally at the level of 'make bluetooth work' rather than at the level of String.Format

我在Android的WinRT,WP,WPF,MonoTouch和Mono上进行了大量PCL工作-请参见 http ://slodge.blogspot.co.uk/p/mvvmcross-quicklist.html 中有许多指向PCL工作的链接.

I do lots of PCL work across WinRT, WP, WPF, MonoTouch and Mono for Android - see http://slodge.blogspot.co.uk/p/mvvmcross-quicklist.html for lots of links to PCL work.

的确,Xamarin曾建议过几年不使用PCL,但是现在这种情况已经改变,并且对PCL的官方支持也在进行中-请参见

It's true that Xamarin have recommended not using PCLs for a couple of years, but that situation has now changed and the official support for PCLs is under way - see http://slodge.blogspot.co.uk/2013/02/the-future-is-portable.html

从开发角度-尤其是从使用重构和测试工具的角度出发-我毫不犹豫地建议您现在使用PCL,尤其是在String.Format级别的操作上.但是,每个项目都是唯一的...因此它并不总是正确的答案.

From a development perspective - especially from the point of view of using refactoring and testing tools - I don't hesitate to recommend you use PCLs now... especially for operations at the String.Format level. However, each project is unique... so it's not always the right answer.

一个重要说明:现在,最好将PCL二进制文件重新用于MonoTouch平台上-现在,针对特定的MonoTouch库平台构建可移植库.参见 http://slodge.blogspot.co.uk/2013/01 /almost-portable-binaries.html?m=1

One important note: right now it's better to not reuse the PCL binary files across to the MonoTouch platform - for now, build your portable libraries against the specific MonoTouch library platform. See http://slodge.blogspot.co.uk/2013/01/almost-portable-binaries.html?m=1

这篇关于MonoTouch:使用可移植类库创建多平台应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆