V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
拼车信息请发到 /go/cosub 节点。 如果没有发送到 /go/cosub,那么会被移动到 /go/pointless。如果持续触发这样的移动,会导致账号被禁用。
henryshen233
V2EX  ›  Surge

Mac App 获取爱词霸的 API 返回的结果通过 Surge 显示马上 completed,但是 GUI 显示结果却很慢,至少得 5 秒后显示

  •  
  •   henryshen233 · 2017-04-30 15:13:11 +08:00 · 247 次点击
    这是一个创建于 2574 天前的主题,其中的信息可能已经有所发展或是发生改变。
    RT,下面放代码
    2 条回复    2017-04-30 15:14:38 +08:00
    henryshen233
        1
    henryshen233  
    OP
       2017-04-30 15:13:54 +08:00
    - (IBAction)searchButton:(id)sender {
    NSString *searchContent = _searchWord.stringValue;
    NSString *urlStr = [[NSString alloc] initWithFormat:@"http://dict-co.iciba.com/api/dictionary.php?w=%@&type=json&key=*********************", searchContent];
    NSURL *url = [[NSURL alloc] initWithString:urlStr];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    request.HTTPMethod = @"GET";
    request.timeoutInterval = 60;
    NSURLSession *session = [NSURLSession sharedSession];
    NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
    NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
    NSString *wordName = [dict valueForKey:@"word_name"];
    _searchResult.stringValue = wordName;
    }];
    [task resume];
    }
    henryshen233
        2
    henryshen233  
    OP
       2017-04-30 15:14:38 +08:00
    请教各位朋友,希望有朋友能够抽出宝贵时间看一眼,谢谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   977 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 22:11 · PVG 06:11 · LAX 15:11 · JFK 18:11
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.