cannot get __NSCFURLSession class under ios 8

2019-09-16 04:03发布

问题:

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")