0

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 ?

jqyao
  • 170
  • 6

3 Answers3

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");
gabbler
  • 13,626
  • 4
  • 32
  • 44
1

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].

mattt
  • 19,544
  • 7
  • 73
  • 84
  • Thanks for answering, mattt. My code is trying to swizzle the methods to intercept the network traffic, like [this sdk](https://github.com/apigee/apigee-ios-sdk/blob/master/source/Classes/Services/ApigeeNSURLSessionSupport.m). I believe swizzling the private class the only solution. – jqyao Oct 16 '14 at 13:03
  • The Foundation URL Loading System actually provides a sanctioned solution by way of `NSURLProtocol`. Use that; don't swizzle. – mattt Oct 16 '14 at 15:34
  • NSURLProtocol won't meet our needs because we want to measure the network performance for each request made by app specifically. NSURLProtocol has several limitations. 1. It catches too many requests, even the one made by webview. 2. Internally, it actually opens another NSURLConnection. 3. Some of the delegate cannot be passed thru the NSURLProtocol implementation. – jqyao Oct 20 '14 at 20:56
0

It looks like Apple has changed this private class to __NSURLSessionLocal

c = NSClassFromString(@"__NSURLSessionLocal")

jqyao
  • 170
  • 6