gpt4 book ai didi

cocoa-touch - 如何根据 ASIHTTPRequest 执行不同的操作?

转载 作者:行者123 更新时间:2023-11-29 13:48:39 25 4
gpt4 key购买 nike

我正在使用 ASIFormDataRequest 将图像上传到 TwitPic,我从这里收到了回复,一切正常。但是在 - (void)requestFinished:(ASIHTTPRequest *)request 上,我已经有了一个 TwitLonger 响应的 Action (可以正常工作)。现在我将如何根据响应类型执行不同的操作?我尝试设置一个字符串并与 if 进行比较,得到响应的最后一件事,但没有成功。这是我尝试过的方式:

- (void)requestFinished:(ASIHTTPRequest *)request
{
NSString *responseString = [request responseString];

NSString *first = [responseString substringFromIndex: [responseString length] - 7];
NSLog(@"%@", first);
if (first == @"</rsp>"+
) {
NSString *responseString = [request responseString];
NSLog(@"%@", responseString);
NSString *result = nil;
// Determine "<div>" location
NSRange divRange = [responseString rangeOfString:@"<mediaurl>" options:NSCaseInsensitiveSearch];
if (divRange.location != NSNotFound)
{
// Determine "</div>" location according to "<div>" location
NSRange endDivRange;

endDivRange.location = divRange.length + divRange.location;
endDivRange.length = [responseString length] - endDivRange.location;
endDivRange = [responseString rangeOfString:@"</mediaurl>" options:NSCaseInsensitiveSearch range:endDivRange];

if (endDivRange.location != NSNotFound)
{
// Tags found: retrieve string between them
divRange.location += divRange.length;
divRange.length = endDivRange.location - divRange.location;

result = [responseString substringWithRange:divRange];
}
tweet.text = result;
NSLog(@"%@", result);
}
} else {

// Use when fetching text data
NSString *responseString = [request responseString];
NSLog(@"%@", responseString);
NSString *result = nil;
// Determine "<div>" location
NSRange divRange = [responseString rangeOfString:@"<content>" options:NSCaseInsensitiveSearch];
if (divRange.location != NSNotFound)
{
// Determine "</div>" location according to "<div>" location
NSRange endDivRange;

endDivRange.location = divRange.length + divRange.location;
endDivRange.length = [responseString length] - endDivRange.location;
endDivRange = [responseString rangeOfString:@"</content>" options:NSCaseInsensitiveSearch range:endDivRange];

if (endDivRange.location != NSNotFound)
{
// Tags found: retrieve string between them
divRange.location += divRange.length;
divRange.length = endDivRange.location - divRange.location;

result = [responseString substringWithRange:divRange];
}
tweet.text = result;
[_engine setAccessToken:token];
[_engine sendUpdate:tweet.text];
[self.parentViewController dismissModalViewControllerAnimated:true];
}
}
}

这是响应的一个例子:

<?xml version="1.0" encoding="UTF-8"?>
<rsp stat="ok">
<mediaid>50ia96</mediaid>
<mediaurl>URL GOES HERE</mediaurl>
</rsp>

最后,我想要的是获取标签之间的 URL。

提前致谢!

最佳答案

Go to their documentation ,然后向下滚动到“在委托(delegate)方法中处理多个请求的成功和失败”部分。他们为您提供了三种选择——大多数情况下,在您发出请求时设置 userInfo 字典就足够了,然后只需在您的回调中读取它并采取适当的行动。一些快速代码:

在创建和启动请求时设置:

request.userInfo = [NSDictionary dictionaryWithObjectsAndKeys: @"firstRequestId", @"id", nil];

然后在你的回调中:

if([[request.userInfo objectForKey:@"id"] isEqualToString:@"firstRequestId"]) {
// Handle the request with id 'firstRequestId'
}

关于cocoa-touch - 如何根据 ASIHTTPRequest 执行不同的操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6081621/

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