数据显示 nil 并且它正在崩溃的数据参数


- (IBAction)loginAction:(id)sender {
    NSString *post =[NSString stringWithFormat:@"Email=%@&Password=%@",self.eMail.text,self.password.text];
    NSString * loginURL = @"http://75.101.159.160:8222/api/mobileappapi/user/login"; // Login URL
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    NSHTTPURLResponse   * response;
    NSError             * error;
    NSMutableURLRequest * request;
    request = [[NSMutableURLRequest alloc]initWithURL:nil cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:60.0];
    [request setHTTPMethod:@"POST"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [request setHTTPBody:postData];
    request.URL = [NSURL URLWithString:[NSString stringWithFormat:@"%@",loginURL]];
    error       = nil;
    response    = nil;
    NSData* jsonUpdateDate = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
   // jsonUpdateDate = [NSURLConnection sendSynchronousRequest:request returningResponse:response error:&error];

    NSDictionary* resultsDictionary = [NSJSONSerialization JSONObjectWithData:jsonUpdateDate options:0 error:&error];
    NSLog(@"%@",resultsDictionary);

    NSString *userRole = [resultsDictionary objectForKey:@"UserRole"];
    if (userRole != (NSString*)[NSNull null]) {
    if ([userRole isEqualToString:@"Passenger"]) {
        // SuccessuserRole
        HomeScreen *obj=[self.storyboard instantiateViewControllerWithIdentifier:@"HomeScreen"];
        [self presentViewController:obj animated:NO completion:nil];
    }
    else if ([userRole isEqualToString:@"Driver"]){
        SelectVehicle *obj=[self.storyboard instantiateViewControllerWithIdentifier:@"SelectVehicle"];
        [self presentViewController:obj animated:NO completion:nil];
        }
    }
}

我无法访问这里的服务

有关完整详细信息,请参阅Apple的Info.plist参考(感谢@gnasher729)。

您可以在 Info.plist 中为特定域添加例外:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>testdomain.com</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSExceptionRequiresForwardSecrecy</key>
            <true/>
            <key>NSExceptionMinimumTLSVersion</key>
            <string>TLSv1.2</string>
            <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
            <false/>
            <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
            <true/>
            <key>NSThirdPartyExceptionMinimumTLSVersion</key>
            <string>TLSv1.2</string>
            <key>NSRequiresCertificateTransparency</key>
            <false/>
        </dict>
    </dict>
</dict>

每个例外域的所有密钥都是可选的。演讲者没有详细说明任何键,但我认为它们都相当明显。

(来源:WWDC 2015 会议 703,"隐私和您的应用程序",30:18)

如果你的应用有充分的理由,还可以使用单个密钥忽略所有应用传输安全限制:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

如果您的应用没有充分的理由,您可能会面临被拒绝的风险:

将 NSAllowsArbitraryLoads 设置为 true 将允许它工作,但是 苹果非常明确,他们打算拒绝使用它的应用程序 没有特定原因的标志。使用的主要原因 NSAllowsArbitraryLoad我能想到的是用户创建的内容 (链接共享、自定义网络浏览器等)。在这种情况下,苹果仍然 希望您包含对 URL 强制执行 ATS 的例外 一切由您掌控。

如果确实需要访问未通过 TLS 1.2 提供的特定 URL,则需要为这些域编写特定的例外,而不是使用 NSAllowsArbitraryLoads 设置为 yes。您可以在 NSURLSesssion WWDC 会话中找到更多信息。

在共享 NSAllowsArbitraryLoads 解决方案时请小心。这不是苹果推荐的修复程序。- Kcharwood(感谢@marco-Tolman)

礼貌 : https://stackoverflow.com/a/30732693/2963912

最新更新