【问题标题】:Asynchronous - My app is not work when I download it from app store?异步 - 当我从应用商店下载时,我的应用无法运行?
【发布时间】:2014-06-30 10:40:31
【问题描述】:

我的应用程序有一个登录页面,人们需要输入密码才能登录。在我将其提交给 iTuneConnect 之前,我的应用程序的所有内容都可以在我的几部 iPhone 上运行,然后它已获得 Apple 的批准。当我从应用商店下载回来时发生了一些事情。 HUD的状态一直在加载中......无法登录进去。

这是我的简单代码:

@synthesize threadCount = _threadCount;


- (void) initData
{
    _codeIsVaild = NO; 
}


- (IBAction)Login:(id)sender
{
    _threadCount = 0;

    //Login procedure
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.mode = MBProgressHUDModeIndeterminate;
        hud.labelText = @"Loading...";
        [hud showAnimated:YES whileExecutingBlock:^{

            [self getData];
            while (_threadCount != 5) {
                //Waiting for all tasks complete...It will be pass when the threads counter is equal 5
            }
        } completionBlock:^{

            if (_codeIsVaild)
            {
                //Password is Vaild
                [self performSegueWithIdentifier:@"loginsegue" sender:self];
            }
            else
            {
                //Show error Alert
            }
            [hud removeFromSuperview];
        }];
    }
}


-(void) getData
{

    dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
    NSString *URLString = [APILink getData];

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];

    [manager POST:URLString parameters:paras
         success:^(AFHTTPRequestOperation *operation, id responseObject)
        {
            //Tasks
            [self taskone];
            [self tasktwo];
            [self taskthree];
            [self taskfour];
            [self taskfive];
            _codeIsVaild = YES;
        }
        else
        {
             _codeIsVaild = NO;
        }
            dispatch_semaphore_signal(semaphore);
        }
    failure:^(AFHTTPRequestOperation *operation, NSError *error)
    {
        _codeIsVaild = NO;
        dispatch_semaphore_signal(semaphore);
    }];
    dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
}


-(void) taskone
{
    NSString *URLString = [APILink taskoneAPIurl];

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];

    [manager POST:URLString parameters:paras
         success:^(AFHTTPRequestOperation *operation, id responseObject) {
             _threadCount += 1;
         }
         failure:^(AFHTTPRequestOperation *operation, NSError *error) {
             _threadCount += 1;
         }];
}

//Same as taskone,but get data from another url
-(void) taskTwo
-(void) taskThree
-(void) taskFour
-(void) taskFive   

我认为问题在于异步任务管理。如果是这样的话,我的所有手机应该都无法登录。最奇怪的是,在我将它上传到应用商店之前它可以在我的手机上正常工作,但是当我从应用商店下载它时它就不能正常工作.我能做些什么?谢谢大家。

【问题讨论】:

  • 终于找到了解决办法,参考网址:How to batch request with AFNetworking 2?这表明代码不能等待几个请求的结果,使用一个死循环来等待。您应该使用 dispatch_group_t 和 dispatch_group_notify 谢谢 CirrusFlyer 和大家!祝你有美好的一天!

标签: ios objective-c asynchronous app-store grand-central-dispatch


【解决方案1】:

终于找到了解决办法,参考网址:How to batch request with AFNetworking 2?

这表示代码不能等待多次请求的结果,使用无限循环等待。

你应该使用 dispatch_group_t & dispatch_group_notify

感谢 CirrusFlyer 和大家!

祝你有美好的一天!

【讨论】:

    【解决方案2】:

    我必须通过调试器观看它以提供任何真正的帮助,但听起来你并没有超越 getData() 方法或者你的 while 循环的停止条件从未满足(我的钱在稍后,因为它似乎没有以线程安全变量开头......如果您的终止条件基于它,这是一个很大的禁忌)。

    作为一个建议,您可能需要添加一些日志记录 - 您可以使用 - 除了确保没有竞争条件之外,还可以用于调试目的。

    【讨论】:

    • 后来从应用商店下载的调试器无法使用问题,所以才问这个​​​​但是在我提交到iTunes connect之前,一切正常,调试器显示结果正常。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-11
    • 2015-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多