Xamarin.iOS,AOT,JIT,Limitations

Since applications on the iPhone using Xamarin.iOS are compiled to static code, it is not possible to use any facilities that require code generation at runtime.

These are the Xamarin.iOS limitations compared to desktop Mono:

Limited Generics Support

Unlike traditional Mono/.NET, code on the iPhone is statically compiled ahead of time instead of being compiled on demand by a JIT compiler.

Mono‘s Full AOT technology has a few limitations with respect to generics, these are caused because not every possible generic instantiation can be determined up front at compile time. This is not a problem for regular .NET or Mono runtimes as the code is always compiled at runtime using the Just in Time compiler. But this poses a challenge for a static compiler like Xamarin.iOS.

Some of the common problems that developers run into, include:

Generic Subclasses of NSObjects are limited

Xamarin.iOS currently has limited support for creating generic subclasses of the NSObject class, such as no support for generic methods. As of 7.2.1, using generic subclasses of NSObjects is possible, like this one:

class Foo<T> : UIView {
    [..]
}

While generic subclasses of NSObjects are possible, there are a few limitations. Read the Generic subclasses of NSObject document for more information

P/Invokes in Generic Types

P/Invokes in generic classes aren‘t supported:

class GenericType<T> {
    [DllImport ("System")]
    public static extern int getpid ();
}

Property.SetInfo on a Nullable Type is not supported

Using Reflection‘s Property.SetInfo to set the value on a Nullable<T> is not currently supported.

Value types as Dictionary Keys

Using a value type as a Dictionary<TKey, TValue> key is problematic, as the default Dictionary constructor attempts to use EqualityComparer<TKey>.Default. EqualityComparer<TKey>.Default, in turn, attempts to use Reflection to instantiate a new type which implements the IEqualityComparer<TKey> interface.

This works for reference types (as the reflection+create a new type step is skipped), but for value types it crashes and burns rather quickly once you attempt to use it on the device.

Workaround: Manually implement the IEqualityComparer<TKey> interface in a new type and provide an instance of that type to the Dictionary<TKey, TValue> (IEqualityComparer<TKey>) constructor.

No Dynamic Code Generation

Since the iPhone‘s kernel prevents an application from generating code dynamically Mono on the iPhone does not support any form of dynamic code generation. These include:

  • The System.Reflection.Emit is not available.
  • No support for System.Runtime.Remoting.
  • No support for creating types dynamically (no Type.GetType ("MyType`1")), although looking up existing types (Type.GetType ("System.String") for example, works just fine).
  • Reverse callbacks must be registered with the runtime at compile time.

System.Reflection.Emit

The lack of System.Reflection. Emit means that no code that depends on runtime code generation will work. This includes things like:

  • The Dynamic Language Runtime.
  • Any languages built on top of the Dynamic Language Runtime.
  • Remoting‘s TransparentProxy or anything else that would cause the runtime to generate code dynamically.

    Important: Do not confuse Reflection.Emit with Reflection. Reflection.Emit is about generating code dynamically and have that code JITed and compiled to native code. Due to the limitations on the iPhone (no JIT compilation) this is not supported.

But the entire Reflection API, including Type.GetType ("someClass"), listing methods, listing properties, fetching attributes and values works just fine.

Reverse Callbacks

In standard Mono it is possible to pass C# delegate instances to unmanaged code in lieu of a function pointer. The runtime would typically transform those function pointers into a small thunk that allows unmanaged code to call back into managed code.

In Mono these bridges are implemented by the Just-in-Time compiler. When using the ahead-of-time compiler required by the iPhone there are two important limitations at this point:

  • You must flag all of your callback methods with the MonoPInvokeCallbackAttribute
  • The methods have to be static methods, there is no support for instance methods.

No Remoting

The Remoting stack is not available on Xamarin.iOS.

Runtime Disabled Features

The following features have been disabled in Mono‘s iOS Runtime:

  • Profiler
  • Reflection.Emit
  • Reflection.Emit.Save functionality
  • COM bindings
  • The JIT engine
  • Metadata verifier (since there is no JIT)

.NET API Limitations

The .NET API exposed is a subset of the full framework as not everything is available in iOS. See the FAQ for a list of currently supported assemblies.

In particular, the API profile used by Xamarin.iOS does not include System.Configuration, so it is not possible to use external XML files to configure the behavior of the runtime.

时间: 2024-10-10 19:35:15

Xamarin.iOS,AOT,JIT,Limitations的相关文章

Xamarin.iOS项目编译提示Could not AOT the assembly

Xamarin.iOS项目编译提示Could not AOT the assembly 错误信息:Could not AOT the assembly **************.dll 这个错误是由于AOT编译文件太大造成的.用户可以尝试修改编译选项.在项目属性窗口中,设置iPhone Build Options,选择Linker Behavior中的Link all assemblies选项

Xamarin.iOS常用控件总结

1.UIButton控件 btn.SetTitle("test", UIControlState.Normal); UIControlState枚举类型使用: Normal:默认可使用状态 Highlighted:当点击控件事件时控件的状态 Disabled:控件状态不可用 Selected:控件选中时的状态 Application: 使用Application的一个附加控件状态 Reserved: UIButton btn = UIButton.FromType(UIButtonTy

Xamarin.IOS之多视图

继上节<Xamarin.IOS之快速入门>之后,本节将会在此基础之上具体扩展,主要是增加一个列表可以提供历史拨打电话的记录.下面我们直接进入正题. 首先打开MainStoryboard.storyboard,我们在这个基础之上继续修改.从工具栏中拖放一个Navigation Controller到故事板中,然后我们可以看到如下所示: 但是当前的主视图控制器还是之前的,我们需要将新的设置为主视图,所以我们要将拖放到下面这个视图控制器,然后我们还需要删除Navigation Controller所

Xamarin.iOS开发初体验

Xamarin是一个跨平台开发框架,这一框架的特点是支持用C#开发IOS.Android.Windows Phone和Mac应用,这套框架底层是用Mono实现的. Mono是一款基于.NET框架的开源工程,包含C#语言编译器.CLR运行时和一组类库,能运行于Windows.Linux.Unix.Mac OS和Solaris.对于.NET程序员来说,Xamarin是走向安卓.iOS.Mac跨平台开发的神器,不仅能用熟悉的C#来开发,还能使用Visual Studio作为IDE.本文内容是Xamar

Xamarin.iOS学习一:Hello.iOS 入门学习

介绍使用Xamarin开发iOS 在这两个章节里面,我们会使用Xamarin Studio 或者Visual Studio 创建第一个Xamarin.iOS程序并且去理解使用Xamarin开发iOS程序的基础概念.接着我们将会介绍创建和部署iOS程序所需要的工具.概念和步骤. Hello.iOS 快速入门 首先我们将创建一个让用户输入字母和数字并且可以拨打号码的应用程序,最终效果图如下:

Xamarin.IOS之快速入门

本人利用业余的时间编写了关于Xamarin.Android的基础教程,获得了很多人的支持.但是笔者打心里想说的就是这个教程所能提供的知识太有限了,等笔者到新的工作后,会开始抓紧时间写一些实战开发中运用的技术以及技巧.现在笔者带着大家进入Xamarin.IOS的入门教程. 关于环境 如果读者是破解的,那么mac这边的破解可能会伤脑筋,笔者使用的商业版的账号.当然我这里建议大家可以到淘宝购买,其实商业版如果以学校机构购买很便宜的.关于环境的讲解就到这吧,下面开始正题(这里推荐一个比较好的QQ群[23

用c#开发苹果应用程序 xamarin.ios方式

Networkcomms网络通信框架来自于英国,支持以xamarin.ios的方式开发苹果应用程序 其开源版本2.3.1中带有一个示例程序,实现聊天功能,只要输入对方手机的IP和端口就能够显示聊天,可以作为学习networkcomms框架的入门程序 using System; using System.Collections.Generic; using System.Linq; using MonoTouch.Foundation; using MonoTouch.UIKit; using N

Xamarin.iOS提供没有匹配的配置文件

Xamarin.iOS提供没有匹配的配置文件 错误信息:No installed provisioning profiles match the installed ios code signing keys. 这是由于没有创建当前App对应的配置文件.该文件需要用户登录苹果开发者网站,使用App标识来创建.创建后,使用Xcode下载并添加到自己的开发账户中,才可以在VS中编译生成App.

Xamarin.iOS 照相機功能的使用 (1) :最簡單的做法

iOS 提供我們幾種不同的方法使用照相機並且儲存於相簿. Xamarin.iOS 當然也可以很快地使用這樣的方法,使用照相機功能. 在這之前我們可以先稍微了解一下基本結構,如下圖. 若是有DirectX (DirectInput) 或是OpenGL ES 操作經驗的朋友就可以發現基本上的概念並沒有差很多.都是從獲取device開始,到準備好接收輸出的 byte[] 並管理,到決定輸出的格式為何. 我們現在先使用最簡單的 UIImagePickerController 來實現照相機功能 btnUI