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 ?
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");
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]
.
It looks like Apple has changed this private class to __NSURLSessionLocal
c = NSClassFromString(@"__NSURLSessionLocal")