包含标签 Xamarin.iOS 的文章

Xamarin开发中我所遇到Error错误的解决办法

Xamarin的坑还是不少的,有些问题可能会一而再,再而三地重复出现,为了避免下一次遇到同一个问题重复的查找,我将在开发中遭遇到的问题汇总在这里,既方便我自己查阅,也提供给别人做参考;以下给出的解决方案中一部分是解决思路,一部分是确实成功地解决了问题的方案(我将用斜体标出)。 1.……

阅读全文

Xamarin.iOS和Xamarin.Android中计算文本宽度的方法

Xamarin.iOS CoreGraphics.CGSize cGSize = new CoreGraphics.CGSize(1000, 1000); public double getDisplayLength(string str) { var s = new NSAttributedString(str); var size = s.GetBoundingRect(cGSize, NSStringDrawingOptions.UsesLineFragmentOrigin, null); return size.Width; } Xamarin.Android Paint paint = new Paint(); public double getDisplayLength(string str) { float[] widths = new float[str.Length]; paint.GetTextWidths(str, widths); float sum = 0; widths.ForEachWithIndex((o, index) => { sum += o; }); return sum; } 其中ForEachWithIndex是我自己写的一个扩展方法,方便遍历数组; public static void ForEachWithIndex<T>(this T[] array, Action<T, int> action) { for (int i = 0; i < array.Length; i++) { action(array[i], i); } }……

阅读全文

在Xamarin.iOS中实现TextLayer的垂直对齐

代码如下: public class SHLCTextLayer : CATextLayer { public SHLCTextLayer(IntPtr handle) : base(handle) { } public SHLCTextLayer() : base() { } public SHLCTextLayer(NSCoder coder) : base(coder) { } public SHLCTextLayer(NSObjectFlag t) : base(t) { } public override void DrawInContext(CGContext ctx) { try { var height = this.Bounds.Size.Height; var fontSize = this.FontSize; var yDiff = (height - fontSize) / 2 - fontSize / 10; ctx.SaveState(); ctx.TranslateCTM((nfloat)0.0f, yDiff); base.DrawInContext(ctx); ctx.RestoreState(); } catch (Exception e) { ErrorReporter.Report(e); } } }……

阅读全文

Xamarin开发获取联系人信息的方法

在输入法开发中,需要获取通讯录的联系人姓名,然后将其编码导入词库中,本文就简单介绍一下两个平台上获取联系人信息的方法; Xamrin.Android平台 1.添加权限申明 在AndroidManifest.xml文件中间添加如下权限申明: <!-- 读取联系人权限,上传联系人需要用到此权限 --> <uses-permission android:name="android.permission.READ_CONTACTS"……

阅读全文

iOS12下跳转出现NSInternalInconsistencyException的解决方法

问题现象 在洛书1.7.5版本中出现这样一个bug:从键盘跳转输入法主程序失败;导入文件时跳转主程序也失败; 调试应用时出现如下错误: Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Application has LSSupportsOpeningDocumentsInPlace key, but doesn't implement application:openURL:options: on delegate <AppDelegate: 0x283eda9c0> 原因分析 跳转时application:openURL:options:不存在导致出错;此前我重载了applicat……

阅读全文

如何用instrument对Xamarin.iOS进行代码级调优

此前我写了一篇如何使用Instrument对Xamarin.iOS应用进行调优,但里面仅仅介绍了如何加载Xamarin.iOS程序,在实际的调试中还是不够用的,有时候为了有的放矢,我们需要深入到代码一级才知道程序出现问题的根源,今天我给大家介绍一下如何用instrument对Xa……

阅读全文

Xamarin.iOS出现Code signing failed问题如何处理

我最近遇到了一个奇怪的问题,项目可以编译,可以运行,但是就是在生成Archvie之后要对其进行sign and distribute时会报如下错误: 并且除此之外,没有其它信息; 我试过所有办法,比如重新生成证书、重建项目、重启IDE和电脑、甚至是移除项目中可疑的子项目的代码等等,但是都不管……

阅读全文

Xamarin.iOS报Reason: no suitable image found.如何处理

在一次项目调试中我遇到了如下问题: 错误信息为: Reason: no suitable image found. Did find: /Users/huangboru/Library/Developer/CoreSimulator/Devices/AD26D1B5-DEE9-4E27-949C-A442CBAB5A8B/data/Containers/Bundle/Application/04F80EC9-7D94-4150-9ADB-1E1BDA867E2D/ThreeDiretion.iOS.app/PlugIns/ThreeDiretionKeyBoard.appex/../../Frameworks/Mono.framework/Mono: required code signature missing for '/Users/huangboru/Library/Developer/CoreSimulator/Devices/AD26D1B5-DEE9-4E27-949C-A442CBAB5A8B/data/Containers/Bundle/Application/04F80EC9-7D94-4150-9ADB-1E1BDA867E2D/ThreeDiretion.iOS.app/PlugIns/ThreeDiretionKeyBoard.appex/../../Frameworks/Mono.framework/Mono' 解决办法: 打开项目的option->iOS Build ,在 “Additional mtouch arguments"中加入--mono:static 即可;……

阅读全文

如何将第三方库封装成Xamarin.iOS链接库

如果你使用的是原生的开发技术,那么你肯定是不需要阅读本文的。但是如果在你的技术栈中,Xamarin.iOS有其一席之地的话,花点时间看一看或者收藏一下本文以备日后查阅,你一定不会吃亏。因为无论是Xamarin官方所提供的文档,抑或是国内所能查找的资料(事实上,几乎找不到),要么已……

阅读全文

Xamarin下获得各平台应用所在文件夹路径的方法

Android: // <AppHome>/files string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal); iOS: // <AppHome>/Documents string docFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal); // to meet Apple’s iCloud terms, content that is not generated by the user // should be placed in the /Library folder or a subdirectory inside it string libFolder = System.IO.Path.Combine(docFolder,"..", "Library"); WindowPhone: // <AppHome>\local string path = Windows.Storage.ApplicationData.Current.LocalFolder.Path;……

阅读全文