Question

I am currently using the following code to animate the transition between a view, and when the refreshTheServers method is called while doing so, the whole application freezes, refreshes the servers, and then shows the view.

How can I make this a seamless process where the view laods and then the servers are refreshed?

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:NO];
[self.view addSubview:self.folderView];
[UIView commitAnimations];
[self refreshTheServers];

EDIT: Here is my code for the refreshTheServers method:

- (void)refreshTheServers {

KeychainItemWrapper* keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"KeychainTest" accessGroup:nil];

NSString *userForConnect = [NSString stringWithFormat:@"%@", [keychain objectForKey:(__bridge id)(kSecAttrAccount)]];
NSString *passForConnect = [NSString stringWithFormat:@"%@", [keychain objectForKey:(__bridge id)(kSecValueData)]];



CTCoreAccount *account = [[CTCoreAccount alloc] init];

dispatch_queue_t taskQ = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

dispatch_async(taskQ, ^{
    [account connectToServer:[[NSUserDefaults standardUserDefaults]
                              stringForKey:@"server"]
                        port:993
              connectionType:CTConnectionTypeTLS
                    authType:CTImapAuthTypePlain
                       login:userForConnect
                    password:passForConnect];

    dispatch_async(dispatch_get_main_queue(), ^{
        // ... the thread is over, do stuff on the main thread ...

        CTCoreFolder *inbox = [account folderWithPath:theAppDelegate.folder];

        NSArray *inboxMessages = [inbox messagesFromUID:1 to:0 withFetchAttributes:CTFetchAttrEnvelope];

        [[self allMessages] removeAllObjects];
        [[self allMessages] addObjectsFromArray:inboxMessages];

        [self.messagesTable reloadData];
    });
});
}

What am I doing wrong?

Was it helpful?

Solution

The following call is synchronous: [inbox messagesFromUID:1 to:0 withFetchAttributes:CTFetchAttrEnvelope]; That's why the application freezes. Instruments CPU sampler could highlight that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top