在我获得我想要的值(异步)iOS之前,Parse.com应用程序会继续前进 [英] Parse.com app goes forward before i get the value I want (async) iOS

查看:45
本文介绍了在我获得我想要的值(异步)iOS之前,Parse.com应用程序会继续前进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用查询FindObjectsInBackgroundWithBlock(assync)从Web服务获取值...我希望在应用加载之前在appdelegate上获取该值.我正在尝试执行此操作,但在检查Web服务以获取价值之前,他仍然加载了该应用程序.我该如何处理?我已经尝试过使用NSTimer.

I use a query FindObjectsInBackgroundWithBlock (assync) to get a value from webservice... I want that value on the appdelegate before the app loads. I'm trying do it but he still load the app before check the webservices to get the value. How can I handle it? I already tried with a NSTimer..

我在-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 中调用了此方法:

-(void)checkUserVersion{
    PFQuery *query = [PFQuery queryWithClassName:@"sqliteversion"]; //1
    // NSNumber *n=databaseVersion;
    [query whereKey:@"user_version" equalTo:[NSNumber numberWithInt:[databaseVersion integerValue]]];//2
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {//4
        if (!error && [objects count]>0) {

            for (PFObject *object in objects) {
                valor1=[[object objectForKey:@"Value"]intValue];
                user_version=[NSNumber numberWithInt:valor1];


            }

        }
    }];
}

推荐答案

您可能需要评估为什么在启动之前需要从Parse.com获得此信息的原因.另外,在启动之前说在启动之前"可能意味着很多事情,并且有许多解决方案不涉及在将第一个视图附加到窗口并显示之前进行所有操作".

You may want to evaluate why it's necessary to have this information from Parse.com before launch. Also, it can mean many things to say "before launch", and there are many solutions that don't involve doing "everything" before the first view is attached to the window and shown.

那是说...在前台运行PFQuery提取.但是,这样做会阻止其余代码的执行.可以使用PFQuery的 findObjects 方法来代替 findObjectsInBackground .我建议不要这样做,而应尝试找出一种方法,以在应用程序已加载时等待查询返回.也许您可以暂停用户交互,但显示加载指示符或其他内容?

That said...run the PFQuery fetch in the foreground. Doing this will block execution of the rest of your code, though. Instead of findObjectsInBackground just use the findObjects method of PFQuery. I would advise against doing this though, and instead try to find out a way to wait for the query to return while the app is already loaded. Maybe you could suspend user interaction but display a loading indicator or something?

这篇关于在我获得我想要的值(异步)iOS之前,Parse.com应用程序会继续前进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆