Xamarin/Mono IOS Limitations

http://developer.xamarin.com/guides/ios/advanced_topics/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:


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

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

P/Invokes in Generic Types

P/Invokes in generic classes aren‘t supported:


1
2
3
4
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-12 11:47:33

Xamarin/Mono IOS Limitations的相关文章

Xamarin Mono 环境搭建(使用Visual Studio 2013 开发android 和 ios )

本文主要介绍Xamarin结合VS2013来开发Android应用程序,主要会介绍Mono和Xamarin的关系,以及整个搭建环境的过程. 一.Mono和Xamarin介绍 1.Mono简介 Mono 是一个由Novell 公司主持的项目.该项目的目标是创建一系列符合ECMA 标准(Ecma-334 和Ecma-335)的.NET 工具,包括C# 编译器和共通语言执行平台.与微软的.NET Framework 不同,Mono 项目不仅可以运行于Windows 系统上,还可以运行于Linux,Fr

Visual Studio 2013 Xamarin for iOS 环境搭建

原文:Visual Studio 2013 Xamarin for iOS 环境搭建 一.Mac安装Xamarin.iOS 1,我的Mac 环境:OSX 10.10.3.Xcode 6.3.2 (使用虚拟机亲测也成功  VMware 11 安装 Mac OS X10.10  ) Xamarin.iOS支持Mac OS 10.7及以上版本 下载安装xcode然后继续↓ Xamarin官网下载xamarininstaller.dmg, 安装前关闭防火墙,安装失败后会自动弹出资源列表(同windows

Xamarin Mono For Android、Monotouch 安装

一.Windows下面的安装 1. 安装环境介绍:    Win8.1 企业版64位或Win7 64.VS2013 update4 2. 安装jdk    到oracle官方下载jdk-8u45-windows-x64.exe并安装,默认是安装到C盘的,根据自己的情况选择目录    添加环境变量JAVA_HOME(其实jdk8已经自动添加了,不加也可以,jdk8以下的版本要手动添加)    C:\Program Files\Java\jdk1.8.0_45    添加环境变量CLASSPATH 

Xamarin开发IOS笔记:切换输入法时输入框被遮住

在进行IOS开发的过程中,出现类似微信朋友圈的交互界面,当用户遇到感兴趣的内容可以进行评论.为了方便评论输入,当出现评论输入框的时候自动将评论输入框移动至键盘的上方,这样方便边输入边查看. 当用户隐藏键盘或者切换输入法的时候需要对输入框位置进行变化,这里需要设定键盘监听方法. 效果如下图: 具体实现方法可以参考Xamarin提供的示例,源代码示例见: https://github.com/xamarin/monotouch-samples/blob/master/BubbleCell/Bubbl

GetBuiltProjectOutputRecursive error running Xamarin Forms iOS on Visual Studio

Seems like I get this weird problem while running Xamarin.iOS on Visual studio. This happened after I updated to the latest Xamarin (today). I have connected to my Mac though. I tried to Google it, no answer... "error MSB4057: The target "GetBui

【Xamarin 开发 IOS --使用 Storyboard Segue 实作 UIViewController 的切换 (实例)】

注意:在vs2015中进行画板之间的导航的时候,使用CTRL+鼠标左键进行导航的设定. 使用 NavigationController 进行 画板的链接.... 使用 Storyboard Segue 实作 UIViewController 的切换 (实例) 博客分类: Phone / IOS / Objective-C / Swift Storyboard 是在 iOS 5 SDK 中才出现的新名词,它其实就是原本的 Xib 档案(Interface Builder),用来制作介面排版方面的工

Xamarin Mono for VS开发窗体标题(Title)乱码解决方案

利用mono for VS开发一个手机程序,结果只有窗体的标题 title部分是乱码,其他所有地方中文都显示正常,很郁闷.百度很久无果.最后发现只要在 VS菜单中 的 文件->高级保存选型中奖编码设置为 Unicode或者UTF8就行了.更改所有有乱码的文件,无论是axml还是.cs 文件.

【Xamarin 开发 IOS --IOS ViewController生命周期】

ViewController ViewController是IOS开发中MVC模式中的C,ViewController是view的controller,ViewController的职责主要包括管理内部各个view的加载显示和卸载,同时负责与其他ViewController的通信和协调. 在IOS中,有两类ViewController,一类是显示内容的,比如UIViewController.UITableViewController等,同时还可以自定义继承自UIViewController的Vi

Xamarin,mono for android 用一个APP启动其他隐藏应用程序

花费了好几个小时测试最终搞定了,Mono for android用一个APP启动其他隐藏应用程序. 直接看代码: 隐藏APP(被启动)要在manifest文件配置如下,去除原本的两个标签,修改成只有一个data <Activity> <activity android:icon="@drawable/icon" android:label="IOCPDroid" android:name="iocpdroid.IOCPActivity&q