简体   繁体   English

Parse.com应用程序在我获得我想要的值(异步)iOS之前前进

[英]Parse.com app goes forward before i get the value I want (async) iOS

I use a query FindObjectsInBackgroundWithBlock (assync) to get a value from webservice... I want that value on the appdelegate before the app loads. 我使用查询FindObjectsInBackgroundWithBlock(assync)从webservice获取值...我想在应用程序加载之前在appdelegate上使用该值。 I'm trying do it but he still load the app before check the webservices to get the value. 我正在尝试这样做,但他仍然加载应用程序,然后检查webservices以获取值。 How can I handle it? 我该怎么处理? I already tried with a NSTimer.. 我已经尝试过NSTimer ..

I called this method in -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions : 我在-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions调用了这个方法-(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];


            }

        }
    }];
}

You can't run any code in your app before it finishes launching. 在完成启动之前,您无法在应用中运行任何代码。 If the value is critical for your app to begin working you'll have to show a "waiting for data" message. 如果该值对您的应用开始工作至关重要,则必须显示“等待数据”消息。

You may want to evaluate why it's necessary to have this information from Parse.com before launch. 您可能想要评估为什么在发布之前必须从Parse.com获取此信息。 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. 此外,它可能意味着许多事情要说“在发布之前”,并且有许多解决方案不涉及在第一个视图附加到窗口并显示之前执行“一切”。

That said...run the PFQuery fetch in the foreground. 那就是说...在前台运行PFQuery fetch。 Doing this will block execution of the rest of your code, though. 但是,执行此操作将阻止执行其余代码。 Instead of findObjectsInBackground just use the findObjects method of PFQuery. 而不是findObjectsInBackground只使用PFQuery的findObjects方法。 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? 也许你可以暂停用户交互,但显示一个加载指示器或什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果用户从我的iOS应用中“标记”某些资料,我可以从parse.com收到某种通知吗? - Can I get some sort of notification from parse.com if a user “flags” certain material from my iOS app? 如何在iOS的parse.com中获取当前安装的徽章值? - How to get the badge value of current installation in parse.com for ios? 每次我点击搜索栏时ios应用程序崩溃,同时从parse.com撤消数据 - ios app crashes each time i click on the search bar, while retreving data from parse.com 我需要通过parse.com(PFObject)在iOS上获得一些帮助 - I need a little help on iOS with parse.com (PFObject) 使用iOS的Parse.com登录屏幕i18n - Parse.com Login screen i18n with iOS 带有Parse.com的iOS应用通知 - iOS App Notification with Parse.com 通过Parse.com iOS获取Facebook朋友 - Get Facebook friends with Parse.com iOS parse.com - 在iOS中获取对象延迟 - parse.com - Get Object delay in iOS 当我查询另一个类时,parse.com试图从User类获取值 - parse.com trying to get a value from a User class once i have queried another class Android应用程序:我可以使用iOS sqlite吗? 如果没有,如何从云中的数据库(Parse.com)创建本地数据库? - Android App: can I use iOS sqlite? If not, how do I create a local database from a database in the cloud (Parse.com)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM