我正试图让生活重新回到iOS 7.1到iOS 8.1的项目中。显然这是一个NewsStand应用程序。我需要能够针对不同的主机名手动验证证书。这一切都发生在willSendRequestForAuthenticationChallenge内。在iOS 7.1上,一切正常。我甚至重新测试了仍在运行7.1的iPad,但它可以工作,但在iOS 8.1上,该方法永远不会被调用。因此,所有资产下载都会失败并调用didFailWithError
并且错误为“The operation couldn’t be completed. (NSURLErrorDomain error -1202.)
”
有谁知道iOS 8.1中可能会发生什么变化?他们没有打电话吗?关于iOS 8.1上的继承是否有任何改变可能影响方法是否被检测和调用?我确实尝试将所有方法都移到顶级课程中,但这似乎没有帮助。这可能是因为使用了“POST”请求吗?
对于我的生活,我没有看到任何明显的代码原因,为什么willSendRequestForAuthenticationChallenge未在iOS 8.1上为NKAssetDownload调用,而是为iOS 7.1调用。我从来没有测试过iOS 8.0,所以我不能肯定地说它没有在那里调用。
请注意,我在iOS 8.1上使用的所有其他URL连接都会调用该方法,因此问题似乎特定于NKAssetDownload(或者至少是我对NKAssetDownload的调用)。
相关代码是:
@implementation myDownloader
{
NKIssue * theIssue; // pointer to the magazine Issue object
NSString * theJsonReceiptArrayBase64String;
NKAssetDownload * theAssetDownload;
NSString * sourceURL;
NSString * theFileName;
NSString * issueUniqueId;
NSURLConnection * theConnection;
NSNumber * expectedFileSize;
}
...
-(myDownloader *)initWithIssueAndIdAndSourceAndFinalPath:(NKIssue *)issue uniqueId:(NSString *)uniqueId source:(NSString *)source fileName:(NSString *)fileName fileSize:(NSNumber *) fileSize Receipt:(NSString *)receipt
{
NSLog(@"initWithIssueAndIdAndSourceAndFinalPath");
self = [super init];
if (self)
{
theIssue = issue;
sourceURL = source;
theFileName = fileName;
issueUniqueId = uniqueId;
expectedFileSize = fileSize;
theJsonReceiptArrayBase64String = receipt;
}
return self;
}
...
- (BOOL)connectionShouldUseCredentialStorage:(NSURLConnection *)connection
{
/* never get here on iOS 8.1 */
return NO;
}
- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
/* never get here on iOS 8.1 */
[self handleAuthenticationOnConnection:connection withChallenge:challenge];
}
...
-(void) downloadPackage
{
CCommunictionMgr * communicator = [CCommunictionMgr instance];
NSMutableURLRequest * thePackageRequest = [communicator generateJsonPostPackageRequest:sourceURL uniqueId:issueUniqueId recieptData:theJsonReceiptArrayBase64String];
theAssetDownload = [theIssue addAssetWithRequest:thePackageRequest];
[theAssetDownload setUserInfo:[NSDictionary dictionaryWithObjectsAndKeys:kASSET_TYPE_PACKAGE, kASSET_TYPE_DK, nil]];
theConnection = [theAssetDownload downloadWithDelegate:self];
}
对象“myDownloader”同时实现NSURLConnectionDelegate,NSURLConnectionDownloadDelegate
headerfile
@interface myDownloader : CConnectionDelegate <NSURLConnectionDelegate, NSURLConnectionDownloadDelegate>
...
在CConnectionDelegate对象内部处理身份验证质询的内容。
如果需要,我很乐意包含其他代码的内容。