cannot get __NSCFURLSession class under ios 8

笑着哭i 提交于 2019-12-12 04:36:44

问题


I have code snippet like this

c = NSClassFromString(@"__NSCFURLSession");

Using ios 7 simulator , I was able to get c

c Class __NSCFURLSession 0x00000001113a2ce8

but under ios 8, I am getting

c Class 0x0 0x0000000000000000

Does anyone have a solution for this ?


回答1:


I think NSCFURLSession is not a real class, and iOS 8 has much stronger class type checking and is able to detect a real class.

Try changing the line to:

c = NSClassFromString(@"NSURLSession");



回答2:


Classes with leading underscores like __NSCFURLSession are private, and should not be accessed directly. Reason being, that when the underlying implementation changes—as it appears to have done between iOS 7 and 8—anything depending on those private implementation details are subject to break.

The actual public class is NSURLSession, which can be accessed with NSClassFromString(@"NSURLSession") or, simply, [NSURLSession class].




回答3:


It looks like Apple has changed this private class to __NSURLSessionLocal

c = NSClassFromString(@"__NSURLSessionLocal")



来源:https://stackoverflow.com/questions/26394514/cannot-get-nscfurlsession-class-under-ios-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!