简体   繁体   中英

NSURLSessionDataTask does not work from unity plugin

I have a native iOS sdk that works great in a native ios app, but when I try wrapping it in a unity plugin and call it from unity on an iOS device (ios v6.1), a specific piece of code of an HTTP request is fired but seems to never return:

NSURL* url = // I init some URL here
NSURLSessionConfiguration* cfg = [NSURLSessionConfiguration defaultSessionConfiguration];

NSURLSession *session = [NSURLSession sessionWithConfiguration:cfg
                                                      delegate:nil
                                                 delegateQueue:nil];
NSMutableURLRequest* req = [NSMutableURLRequest requestWithURL:url];
req.HTTPMethod = @"POST";

// send the request
NSURLSessionDataTask *dataTask =
    [session dataTaskWithRequest:req
               completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                   // THIS NEVER GETS CALLED FROM WITHIN A UNITY APP
               }
     ];

[dataTask resume];

Any ideas why? ps I am using NSURLSession because I need to configure things like special headers, etc, and it seems to be the recommended approach for modern iOS versions..

thanks...

发现了问题:测试设备是iOS 6.x,而NSURLSesssionXXX类是iOS7 +,但是奇怪的是,统一的xcode项目没有对此进行任何说明,在运行时也没有任何异常。。我改用NSURLConnection操作队列与iOS 6.x兼容...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM