Macos 为什么我的代码在一次调用此方法时中断,而在另一次调用时中断?

Macos 为什么我的代码在一次调用此方法时中断,而在另一次调用时中断?,macos,cocoa,nsurlconnection,Macos,Cocoa,Nsurlconnection,我有一个Mac应用程序,它应该为给定的用户名获取Twitter关注者和朋友,然后依次向Twitter询问每个返回用户名的用户名。正如您在下面看到的,我有一个方法可以调用twitterapi来获得朋友/追随者(这很好)。是userNameForUserID:delegate:方法导致了我的问题。我过去常常同步执行这些请求,然后立即返回用户名的NSString。这条(现在被注释掉了)线总是断开,所以我尝试用一个NSURLConnection异步地完成它。还是不行。我不明白为什么 [[NSString

我有一个Mac应用程序,它应该为给定的用户名获取Twitter关注者和朋友,然后依次向Twitter询问每个返回用户名的用户名。正如您在下面看到的,我有一个方法可以调用twitterapi来获得朋友/追随者(这很好)。是userNameForUserID:delegate:方法导致了我的问题。我过去常常同步执行这些请求,然后立即返回用户名的NSString。这条(现在被注释掉了)线总是断开,所以我尝试用一个NSURLConnection异步地完成它。还是不行。我不明白为什么 [[NSString alloc]initWithContentsOfURL:…]适用于fetchFollowers。。。方法,但不是当我用完全相同的方法在另一个

我在用于alloc init NSString和URL内容的行上放置了一个断点,当我进入它时,它不会中断、返回、抛出异常、崩溃……什么都没有。就好像这条线刚刚被跨过(但我的应用程序仍然被阻止)

有什么想法吗?非常感谢

NSString * const GET_FOLLOWERS = @"https://api.twitter.com/1/followers/ids.json?cursor=-1&screen_name=";
NSString * const GET_FRIENDS = @"https://api.twitter.com/1/friends/ids.json?cursor=-1&screen_name=";
NSString * const GET_USER_INFO = @"https://api.twitter.com/1/users/show.json?user_id=";

@implementation TwitterAPI

+ (void)userNameForUserID:(NSNumber *)userID delegate:(id<UserNameDelegate>)delegate
{
    NSURL *url = [NSURL URLWithString:[GET_USER_INFO stringByAppendingString:[userID stringValue]]];

    //  NSString *JSON = [[NSString alloc] initWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&error];

    NSURLRequest *req = [NSURLRequest requestWithURL:url];
    NSOperationQueue *queue = [[NSOperationQueue alloc] init];
    [NSURLConnection sendAsynchronousRequest:req queue:queue completionHandler:^(NSURLResponse *urlResponse, NSData *data, NSError *error) {
        [delegate addUserNameToArray:data];
    }];
}

+ (NSArray *)fetchFollowersWithUserName:(NSString *)userName
{
    NSURL *url = [NSURL URLWithString:[GET_FOLLOWERS stringByAppendingString:userName]];

    NSArray *followerIDs;

    NSString *JSON = [[NSString alloc] initWithContentsOfURL:url encoding:NSASCIIStringEncoding error:nil];
    if ([JSON rangeOfString:@"error"].location == NSNotFound)
        followerIDs = [[JSON JSONValue] valueForKey:@"ids"];

    return followerIDs;

}
NSString*const GET_FOLLOWERS=@”https://api.twitter.com/1/followers/ids.json?cursor=-1&screen_name=“”;
NSString*const GET_FRIENDS=@”https://api.twitter.com/1/friends/ids.json?cursor=-1&screen_name=“”;
NSString*const GET_USER_INFO=@”https://api.twitter.com/1/users/show.json?user_id=";
@TwitterAPI的实现
+(void)userNameForUserID:(NSNumber*)userID委托:(id)委托
{
NSURL*url=[NSURL URLWithString:[GET_USER_INFO stringByAppendingString:[userID stringValue]];
//NSString*JSON=[[NSString alloc]initWithContentsOfURL:url编码:NSUTF8StringEncoding错误:&错误];
NSURLRequest*req=[nsurlRequestRequestWithURL:url];
NSOperationQueue*队列=[[NSOperationQueue alloc]init];
[NSURLConnection sendAsynchronousRequest:req队列:队列完成处理程序:^(NSURLResponse*urlResponse,NSData*data,NSError*error){
[委托AddUsernameTarray:数据];
}];
}
+(NSArray*)获取FollowersWithUserName:(NSString*)用户名
{
NSURL*url=[NSURL URLWithString:[GET_FOLLOWERS stringByAppendingString:userName]];
NSArray*followerIDs;
NSString*JSON=[[NSString alloc]initWithContentsOfURL:url编码:NSASCIIStringEncoding错误:nil];
if([JSON rangeOfString:@“error”].location==NSNotFound)
followerIDs=[[JSON JSONValue]valueForKey:@“ids”];
返回跟随者;
}

它抛出了什么样的异常?为什么您的
initWithContentsOfURL
中的一个使用UTF-8编码,而另一个使用ASCII?@fvwmer没有抛出异常或其他任何异常…就像调试器放弃了这一行。@torrey.lyons oops…我原来两者都是一样的;我更改了userNameForUserID中的一个,以查看是否会发生异常至少抛出一个错误…运气不好!即使sendAsynchronous也无法工作。返回的数据或URL请求中是否存在导致代码在该行停止响应的内容(initWithContentsOfURL)?为什么它不会超时、崩溃或出错?我已经等了10分钟以上,等待这些事情发生。仍然没有运气。谢谢大家!