简体   繁体   English

当我的字符串中没有表情符号时,NSString崩溃

[英]NSString crash when I don't have emoji in my string

I have a conversational view on my application. 我对我的应用程序有一个对话视图。 I want to display emoji on the good way in this view. 我想以这种方式很好地显示表情符号。 So I stock my text on a NSString create with the parameter encoding set to : "NSStringEncoding.NonLossyASCII". 因此,我将文本存储在参数编码设置为“ NSStringEncoding.NonLossyASCII”的NSString创建中。 It works when I have an emoji on my string. 当我的字符串上有表情符号时,它可以工作。 But when there is no emoji on the string, there is a crash with the log : 但是,当字符串上没有表情符号时,日志就会崩溃:

Exception masked Exception: Could not initialize an instance of the type 'Foundation.NSString': the native 'initWithData:encoding:' method returned nil. 屏蔽的异常异常:无法初始化类型为Foundation.NSString的实例:本机的“ initWithData:encoding:”方法返回nil。 It is possible to ignore this condition by setting MonoTouch.ObjCRuntime.Class.ThrowOnInitFailure to false. 通过将MonoTouch.ObjCRuntime.Class.ThrowOnInitFailure设置为false,可以忽略此条件。 at (wrapper managed-to-native) ObjCRuntime.Messaging:void_objc_msgSend_IntPtr_IntPtr_bool (intptr,intptr,intptr,intptr,bool) at Foundation.NSObject.InvokeOnMainThread (System.Action action) [0x00007] in /Users/builder/data/lanes/3988/e02d2723/source/xamarin-macios/src/Foundation/NSObject2.cs:560 在(包装器托管到本地)ObjCRuntime.Messaging:void_obj_msgSend_IntPtr_IntPtr_bool(intptr,intptr,intptr,intptr,bool)在/ Users / builder / data /中的Foundation.NSObject.InvokeOnMainThread(System.Action操作)[0x00007] 3988 / e02d2723 / source / xamarin-macios / src / Foundation / NSObject2.cs:560

Is it possible to check if there's emoji on a string or not? 是否可以检查字符串上是否有表情符号? Thank you 谢谢

There is no way emojis can be expressed using ASCII encoding (it is ancient and contains only 128 essential characters). 不能使用ASCII编码来表达表情符号(它很古老,仅包含128个基本字符)。 For this reason string initialization fails (as suggested by the error message). 因此,字符串初始化失败(错误消息建议)。 Use another encoding ( NSUTF8StringEncoding should work). 使用其他编码( NSUTF8StringEncoding应该起作用)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么当我在 DataGrid 中做了一些更改时,我的 ObservableCollection 没有任何更改? - Why I don't have any changes in my ObservableCollection when I have made some in my DataGrid? 当我无权访问 HttpContext 时,如何填充我的审核日志 UserId 字段? - How can I populate my audit log UserId field when I don't have access to HttpContext? 我的项目中没有“添加引用” - I don't have "add reference" in my project 为什么我的 javascript 正在调用回发而我没有错误? - Why my javascript is calling a postback and i don't have error? 当我的表上没有任何nvarchar时,如何解决“将nvarchar数据类型转换为数值错误”的问题? - How can i solve “error converting data type nvarchar to numeric” when i don't have any nvarchar on my table? 为什么我必须在不必使用关键字static时使用? - Why must I use keyword static when they don't have to? 没有默认数据库时的Entity Framework 6和迁移 - Entity Framework 6 and migration when I don't have a default Database "当我没有键值时更新表" - Update of Table when I don't have the key value 运行“ GC.Collect”可修复我的崩溃问题,但我不明白为什么 - Running a 'GC.Collect' fixes my crash, but I don't understand why 当我使用Update方法时,我的updatePanel不更新 - My updatePanel don't update when I use the Update method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM