Code Monkey home page Code Monkey logo

hybunicodereadable's Introduction

HYBUnicodeReadable

解决打印日志对于Unicode编码不能正常显示中文的问题,只需要将文件导入工程,不需要引用,就能达到打印日志显示Unicode编码中文数据

#用途

在开发中,通常希望在console中打印出的信息能够显示出Unicode编码对应的中文,由此作者研究了一下如何解决此问题。 在这里,将此解决方案贡献给大家,如果觉得有用,请给个star!

#安装使用

支持cocoapods:

pod 'HYBUnicodeReadable', '~> 1.1'

或者直接下载源代码然后拖入工程即可!!!

注意:不需要引入头文件一样可以使用的!!!

#效果图

image

#version 1.0

增加对NSData类型的数据的可视化打印,如下:

NSString *str = @"我是转换成data格式的字符串";
  NSData *dataString = [NSData dataWithBytes:str.UTF8String length:str.length];
  NSDictionary *dataSet = @{@"key": @"字典转成data",
                            @"key1": @"在set、数组、字典中嵌套"};
  NSData *dataSetItem = [NSJSONSerialization dataWithJSONObject:dataSet options:NSJSONWritingPrettyPrinted error:nil];
  
  NSMutableSet *set = [NSMutableSet setWithArray:@[@"可变集合", @"字典->不可变集合->可变集合", dataSetItem]];
  NSDictionary *dict = @{@"name"  : @"标哥的技术博客",
                         @"title" : @"http://www.huangyibiao.com",
                         @"count" : @(11),
                         @"dataString" : dataString,
                         @"results" : [NSSet setWithObjects:@"集合值1", @"集合值2", set , nil],
                         @"summaries" : @[@"sm1", @"sm2", @{@"keysm": @{@"stkey": @"字典->数组->字典->字典"}}, dataSetItem],
                         @"parameters" : @{@"key1" : @"value1", @"key2": @{@"key11" : @"value11", @"key12" : @[@"三层", @"字典->字典->数组"]}, @"key13": dataSetItem},
                         @"hasBug": @[@"YES",@"NO"],
                         @"contact" : @[@"关注博客地址:http://www.huangyibiao.com", @"QQ群: 324400294", @"关注微博:标哥Jacky", @"关注GITHUB:CoderJackyHuang"]};
  NSLog(@"%@", dict);

打印结果为:

2015-12-31 16:47:42.352 demo[58176:2693559] 	{
	hasBug = 	(
		"YES",
		"NO",
	),
	dataString = "我是转换成",
	title = "http://www.huangyibiao.com",
	count = 11,
	results = 	{(
		"集合值2",
		"集合值1",
			{(
			"可变集合",
			"字典->不可变集合->可变集合",
				{
				key = "字典转成data",
				key1 = "在set、数组、字典中嵌套",
			},
		)},
	)},
	summaries = 	(
		"sm1",
		"sm2",
			{
			keysm = 	{
				stkey = "字典->数组->字典->字典",
			},
		},
			{
			key = "字典转成data",
			key1 = "在set、数组、字典中嵌套",
		},
	),
	contact = 	(
		"关注博客地址:http://www.huangyibiao.com",
		"QQ群: 324400294",
		"关注微博:标哥Jacky",
		"关注GITHUB:CoderJackyHuang",
	),
	name = "标哥的技术博客",
	parameters = 	{
		key1 = "value1",
		key13 = 	{
			key = "字典转成data",
			key1 = "在set、数组、字典中嵌套",
		},
		key2 = 	{
			key11 = "value11",
			key12 = 	(
				"三层",
				"字典->字典->数组",
			),
		},
	},
}

#Version1.1

增加条件编译,只对Debug环境下起作用

#讲解

为了更详细地说明如何使用,笔者写了一篇博文,大家可以阅读:http://www.huangyibiao.com/ios-unicode-readable/

#维护

笔者会一直维护,如果使用过程中出现任何bug,请反馈给作者,谢谢您的支持!!!

#关注我

如果在使用过程中遇到问题,或者想要与我交流,可加入有问必答QQ群:324400294

关注微信公众号:iOSDevShares

关注新浪微博账号:标哥Jacky

#支持并捐助

如果您觉得文章对您很有帮助,希望得到您的支持。您的捐肋将会给予我最大的鼓励,感谢您的支持!

支付宝捐助 微信捐助
image image

hybunicodereadable's People

Contributors

coderjackyhuang avatar yikibug avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hybunicodereadable's Issues

Thread 1: EXC_BAD_ACCESS (code=1, address=0x18)造成系统崩溃问题

使用Cocoapods 导入的最新框架,在iOS 11.0.2 系统上运行。

打开APP就会直接崩溃报错:
Xcode 断点定位在 NSObject+HYBUnicodeReadable.m 文件的description方法:

另外 Edit Scheme 设置中

  • 环境变量 OS_ACTIVITY_MODE = enable
  • 勾选了僵尸调试Zombie Objects

没有网络时,调用触发闪退,日志如下,调试时也发现,( value = [self valueForKey:propertyName];) propertyName为nil 导致的crash

Date/Time: 2017-11-15 10:50:04.8824 +0800
Launch Time: 2017-11-15 10:37:07.8401 +0800
OS Version: iPhone OS 11.0 (15A372)
Baseband Version: 6.17.00
Report Version: 104

Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 0

Application Specific Information:
abort() called

Filtered syslog:
None found

Last Exception Backtrace:
0 CoreFoundation 0x186553d38 __exceptionPreprocess + 124
1 libobjc.A.dylib 0x185a68528 objc_exception_throw + 55
2 CoreFoundation 0x1865611f8 -[NSObject+ 1372664 (NSObject) doesNotRecognizeSelector:] + 139
3 UIKit 0x18fd1acc4 -[UIResponder doesNotRecognizeSelector:] + 295
4 CoreFoundation 0x1865596e4 forwarding + 1379
5 CoreFoundation 0x18643f0dc _CF_forwarding_prep_0 + 91
6 xxxxxxx 0x10117365c -[NSObject(HYBUnicodeReadable) description] + 2340444 (NSObject+HYBUnicodeReadable.m:38)

7 Foundation 0x186e38a60 _NSDescriptionWithLocaleFunc + 107
8 CoreFoundation 0x1865126fc __CFStringAppendFormatCore + 11587
9 CoreFoundation 0x186513658 _CFStringCreateWithFormatAndArgumentsAux2 + 131
10 CoreFoundation 0x1865406c8 _CFLogvEx2Predicate + 155
11 CoreFoundation 0x186540a70 _CFLogvEx3 + 475
12 Foundation 0x186f23524 _NSLogv + 127
13 Foundation 0x186e48094 NSLog + 31

UItextField获得焦点时,使用系统键盘以外第三方键盘导致App闪退

使用pod引入库文件。
Xcode 7.3
iOS 9.3.2
控件:UITextFiled
事件:ShouldBeginEdit,DidBeginEdit能够走完。
在iOS中使用系统键盘时,点击UITextField时,一切正常。一旦iOS中安装搜狗/百度/讯飞第三方输入法,在输入时正好是第三方输入法时,App闪退。使用全局断点跟踪,跟踪到是NSObject+HYBUnicodeReadable.m第38行
2016-06-09 17 07 49
console里报错是:
2016-06-09 17 08 27
移除库文件后,此问题解决。

启动奔溃

image
真机,启动后崩溃,显示崩溃位置在友盟的一个方法,使用的友盟为 6.9.3

集成微信(精简版0.2M)

pod 'UMCShare/Social/ReducedWeChat'

打印字符串的问题

是否需要转义一下?原先打印出来的是会转义过的
只是调试看看倒是没什么问题..就是觉着有些怪

iPhone 5s , v10.2.1, Crash

下面是抓到的日志

17:38:56 SmartHome(libsystem_trace.dylib)➜subsystem: com.apple.Accessibility, category: IPC, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
17:38:56 SmartHome(HYBUnicodeReadable)➜_defaultHandler
17:38:56 SmartHome(HYBUnicodeReadable)➜_serverRunLoopSource
17:38:56 SmartHome(HYBUnicodeReadable)➜_clientInvalidationSource
17:38:56 SmartHome(HYBUnicodeReadable)➜_serverPort
17:38:56 SmartHome(HYBUnicodeReadable)➜_clientInvalidationPort
17:38:56 SmartHome(HYBUnicodeReadable)➜_validSecurityTokens
17:38:56 SmartHome(CoreFoundation)➜-[AXIPCServer validSecurityTokens]: unrecognized selector sent to instance 0x1700d0ca0
17:38:56 SmartHome(CoreFoundation)➜*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AXIPCServer validSecurityTokens]: unrecognized selector sent to instance 0x1700d0ca0'

奇怪的地方是,我用线连着xcode调试的时候不会崩溃,把掉线后,一打开APP,立马崩溃。
测试用的iPhone 6,6s,6 Plus都没有这个问题,只有老总的iPhone 5s出现了,好尴尬😓。

一进入断点,控制台就疯狂log两个日志,点击继续运行无反应,设置关闭xcode都不行,一直强退xcode才可以

版本:xcode 9.4.1 (9F2000),iOS11.4
2018-07-17 10:05:05.168998+0800 DSTCar[3401:73231] storage
2018-07-17 10:05:05.169247+0800 DSTCar[3401:73231] cow
2018-07-17 10:05:05.169403+0800 DSTCar[3401:73231] storage
2018-07-17 10:05:05.169605+0800 DSTCar[3401:73231] cow
2018-07-17 10:05:05.169789+0800 DSTCar[3401:73231] storage
2018-07-17 10:05:05.169949+0800 DSTCar[3401:73231] cow
2018-07-17 10:05:05.170183+0800 DSTCar[3401:73231] storage
ps:疯狂打印这两行日志

新版1.2引入后会导致FMDB报错

更新到1.2之后引起fmdb初始化错误,如果将库移除了fmdb初始化就正常了

错误日志:
2016-05-31 16:12:30.878 dituwuyou[661:200721] -DBModel init: /var/mobile/Containers/Data/Application/B95688FA-57B3-44DC-8148-750E39FDB8FC/Documents/dituwuyou.sqlite
2016-05-31 16:12:30.895 dituwuyou[661:200721] _path
2016-05-31 16:12:30.895 dituwuyou[661:200721] _queue
2016-05-31 16:12:30.895 dituwuyou[661:200721] _db
2016-05-31 16:12:30.895 dituwuyou[661:200721] -[FMDatabaseQueue db]: unrecognized selector sent to instance 0x12df5bcc0
2016-05-31 16:12:30.896 dituwuyou[661:200721] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FMDatabaseQueue db]: unrecognized selector sent to instance 0x12df5bcc0'
*** First throw call stack:
(0x18201adb0 0x18167ff80 0x182021c4c 0x18201ebec 0x181f1cc5c 0x1005c6a58 0x1828fe3cc 0x181fe455c 0x181fe2464 0x1828fe320 0x1828fe1f0 0x1004850d8 0x1004852e0 0x100484ddc 0x100371240 0x10036e7f4 0x10038e864 0x1871ee9c0 0x18741e184 0x1874225f0 0x18741f764 0x1839bb7ac 0x1839bb618 0x1839bb9c8 0x181fd109c 0x181fd0b30 0x181fce830 0x181ef8c50 0x1871e794c 0x1871e2088 0x1004014b8 0x181a968b8)
libc++abi.dylib: terminating with uncaught exception of type NSException

执行的效率问题

这样做,在输出大段结构复杂的字符的时候,可能会影响.不过 还是 很方便.赞一个

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.