多线程iOS,快速启动UI
在我的ios应用程序中,我加入了谷歌、facebook和twitter的整合。当应用程序启动时,它在加载UI之前加载API 如何在我的UI加载时多线程,首先快速启动。我的Did FinishLaunchingwithOptions是多线程iOS,快速启动UI,ios,objective-c,xcode,multithreading,Ios,Objective C,Xcode,Multithreading,在我的ios应用程序中,我加入了谷歌、facebook和twitter的整合。当应用程序启动时,它在加载UI之前加载API 如何在我的UI加载时多线程,首先快速启动。我的Did FinishLaunchingwithOptions是 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { dispatch_async( d
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Add code here to do background processing
//
//
NSLog(@"Thread Excecution started");
NSError* configureError;
[[GGLContext sharedInstance] configureWithError: &configureError];
NSAssert(!configureError, @"Error configuring Google services: %@", configureError);
[GIDSignIn sharedInstance].delegate = self;
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
dispatch_async( dispatch_get_main_queue(), ^{
// Add code here to update the UI/send notifications based on the
// results of the background processing
NSLog(@"Thread Excecution completed");
});
});
return YES;
}
如果您使用的是多线程,那么可以使用dispatch_group概念
dispatch_group_t group = dispatch_group_create();
//block 1
dispatch_group_async(group, dispatch_get_global_queue(0, 0), ^{
// code here
});
//block 2
dispatch_group_async(group, dispatch_get_global_queue(0, 0), ^{
// code here
});
//block 3
dispatch_group_notify(group, dispatch_get_global_queue(0, 0), ^{
// block 3 will get notify, after block 1 and block 2 complete their tasks.
dispatch_async(dispatch_get_main_queue(), ^{
[animationImageView stopAnimating];
[self createUI];
});
}
块1和块2将并行运行,完成工作后,块3将收到通知 你知道,即使在主线程上,也不能保证通知何时实际发出并被接收,对吗?您确定要这样做吗?为什么您需要在后台线程中编写外部API的启动代码?我可以在Viewdidload中添加这些代码吗?如果需要,您可以使用NSOperationQueue手动处理每个线程。再说一次,您在AppDidLaunch中执行此操作的具体问题是什么?不,如果框架说在AppDelegate中启动它,那么这就是你必须做的。现在还不清楚你到底有什么问题,你在寻求什么