UIImagePickerController在ios7中没有显示(花费更多时间加载)相机预览
我在我的应用程序中使用GCD来获取后台队列中的大量图像和数据,当我呈现uiimagepickercontroller时,它需要更多时间来显示相机预览。谷歌搜索后,我发现许多人在iOS 7中遇到过这个问题,这里还有一篇对我有用的帖子。 ( iOS 7 UIImagePickerController相机无图像)。解决方案是停止后台线程然后呈现选择器控制器。但我真的很难过,不知道如何停止或暂停后台线程,呈现选择器控制器,然后恢复/启动后台线程。有人可以帮我解决这个问题吗。
I am using GCD in my app to fetch lot of images and data in the background queue and when I present uiimagepickercontroller it takes more time to show the camera preview. After googling around, I found that many have faced this issue with iOS 7 and here is one more post that made some sense to me. (iOS 7 UIImagePickerController Camera No Image). The solution was to stop the background threads and then present the picker controller. But I am really stumped and don't know how to stop or pause the background threads, present the picker controller and then resume/start the background thread. Can someone please help me with this.
以下是我在网络课上(和其他人一样)在后台获取图像和数据的方法。我的串行队列初始化如下。
Here is how I am doing my background fetching of images and data in my networking class (like everyone else). My serial queue is initialized like this.
sharedInstance.serialQueue = dispatch_queue_create("user-detail-queue", DISPATCH_QUEUE_CONCURRENT);
在后台获取内容的代码就是这样。
And the code to fetch things in the background is like this.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
NSString *myUserID = [JNKeychain loadValueForKey:@"userID"];
NSString *sessionToken = [JNKeychain loadValueForKey:@"sessionToken"];
if(sessionToken && myUserID)
{
dispatch_async([BGNetworkAPI sharedInstance].serialQueue, ^{
id object = [[BGNetworkAPI sharedInstance].userCache objectForKey:myUserID];
if(object)
{
NSDictionary *cachedResponseDictionary = (NSDictionary *)object;
BGUser *user = [BGUser createUserWithResponseDictionary:cachedResponseDictionary];
if(block)
{
block(user, nil);
}
}
else
{
[[BGUserManagementClient sharedClient] fetchUserDetailsWithUserId:myUserID withSessionToken:sessionToken withSuccessBlock:^(AFHTTPRequestOperation *operation, id responseObject)
{
//NSLog(@"The response object of my user object is %@",responseObject);
[[BGNetworkAPI sharedInstance].userCache setObject:responseObject forKey:myUserID];
NSDictionary *responseDictionary = (NSDictionary *)responseObject;
BGUser *user = [BGUser createUserWithResponseDictionary:responseDictionary];
if(block)
{
block(user,nil);
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
NSLog(@"The error while fetching the user details is %@", operation.responseObject);
if(block)
{
block(nil, error);
}
}];
}
}
});
使用上面的代码,你没有进行提取backgroud为 dispatch_get_main_queue()
为您提供运行该接口的队列。要执行后台提取,您必须使用 dispatch_queue_create(image_queue,NULL)
打开另一个队列。
With the code above you are not doing the fetching in the backgroud as dispatch_get_main_queue()
gives you the queue the interface is running on. To perform a background fetch you have to open another queue with dispatch_queue_create("image_queue", NULL)
.
backgroud fetch已完成,您希望在主队列中使用UI执行此操作。
When the backgroud fetch is finished and you want to do something with the UI you have to do this in the main queue.
dispatch_async(dispatch_get_main_queue(),^{
if(block) {
block(user,nil)
}
});