gpt4 book ai didi

ios - 在 iOS 9.0 中使用服务

转载 作者:行者123 更新时间:2023-11-29 01:46:43 25 4
gpt4 key购买 nike

我已经实现了以下用于在 iOS 中使用服务的代码。

NSString *urlStr=[NSString stringWithFormat:@“SomeURL”];
NSString *jsonStr=[NSString stringWithFormat:@“{\”SomeParameter\”:\”%@\”}”];
NSData *postData = [jsonStr dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:urlStr]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];

NSURLResponse *response;
NSData *POSTReply = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
NSString *theReply = [[NSString alloc] initWithBytes:[POSTReply bytes] length:[POSTReply length] encoding: NSUTF8StringEncoding];
SBJSON *parser = [[SBJSON alloc] init];
NSArray *arryTerritory = (NSArray *) [parser objectWithString:theReply error:nil];

NSLog(@“%@”,[arryTerritory description]);

这是我使用 xCode 6.4 运行代码时的代码,iOS 9.0 能够接收 NSData *postDataNSString *postLength 中的数据。

但在使用 iOS 9.0 编译代码时,我无法获取数据。

OutPut 为nil

使用 xCode 7 Beta 中的服务是否有任何不同的过程。需要与这些版本兼容的 ipa。

最佳答案

在这里,我应该在 info.plist 需要安全通信的地方添加减速。这是我添加到我的 info.plist 中的代码。我认为它是 ios 9 和 xCode 7 bete 版本中的新代码。

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

关于ios - 在 iOS 9.0 中使用服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31832094/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com