2

我有一个用 cocoapods 构建的 Xcode 项目。它只有 Objective C 代码。我想集成核心 Spotlight 框架来为我的应用程序提供本机搜索功能。该应用程序使用 AFNetworking 进行所有网络调用。但是,当我使用 http 协议连接到服务器时,我目前收到此错误。

"desc __NSCFConstantString * @"无法加载资源,因为应用程序传输安全策略需要使用安全连接。" 0x04d9d6ac

我没有在服务器端实现 HTTPS 协议,所以它现在只是 http。相同的代码库与 Xcode 6.x 和 iOS 8.3 SDK 完美配合。任何想法可能是什么原因?其他人是否面临类似的问题?

以下是我的应用程序的代码片段。

 NSMutableURLRequest *request = [serializer requestWithMethod:@"GET" URLString:url parameters:parameters error:nil];

AFHTTPRequestOperation *requestOperation = [[AFHTTPRequestOperation alloc] initWithRequest:request];


[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
    [RESTSessionManager sharedSession:profile];
    NSDictionary *json =
    [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
    NSMutableArray* entries = json[@"entries"];
    NSDictionary *content = [entries[0] objectForKey:@"content"];
    NSDictionary *properties = [content objectForKey:@"properties"];
    profile.repoUserName=  [properties objectForKey:@"user_name"];
    success(operation, responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSString *desc = [[error userInfo] objectForKey:@"NSLocalizedDescription"];

    if( [desc isEqual:@"The network connection was lost."] || [desc isEqual:@"Could not connect to the server."] || [desc isEqual:@"The request timed out."])
        offline();
    else
        failure(operation, error);
}];
4

0 回答 0