我正在尝试让从 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
头文件
@interface myDownloader : CConnectionDelegate <NSURLConnectionDelegate, NSURLConnectionDownloadDelegate>
...
其中身份验证质询的内容在 CConnectionDelegate 对象内处理。
如果需要,我很乐意包含其他代码的内容。