0
-(void)application :(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{

    [self addMessageFromRemoteNotification:userInfo updateUI:NO];

}

I need to run above method in performSelectorInBackground method.but there is option with single object.How do i change my code?

user2134883
  • 255
  • 1
  • 2
  • 9
  • Wrap the objects you need to send in an array. :) – Luke Mar 27 '13 at 11:08
  • 1
    I believe this is what you're looking for as a reference: http://stackoverflow.com/questions/8439052/ios-how-to-implement-a-performselector-with-multiple-arguments-and-with-afterd – Jai Govindani Mar 27 '13 at 11:15

2 Answers2

2

use GCD:

-(void)application :(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [self addMessageFromRemoteNotification:userInfo updateUI:NO];
    });

}

dispatch_async returns immediately, and then the block will execute asynchronously in the background.

Dmitry Zhukov
  • 1,809
  • 2
  • 27
  • 35
2

There is no way to pass multiple parameters via performSelectorInBackground. The way I solve the issue when I encounter it is passing a dictionay, this is made easier with the literal NSDictionary syntax.

-(void)application :(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    [self performSelectorInBackground:@selector(backgroundMethod:) withObject:@{@"userInfo" : someUserInfoDictionary, @"updateUI" : @(NO)}];
}
-(void)backgroundMethod:(NSDictionary *)params
{
    [self addMessageFromRemoteNotification:params[@"userInfo"] updateUI:[params[@"updateUI"] boolValue]];
}
Zaky German
  • 14,324
  • 4
  • 25
  • 31
  • [self performSelectorInBackground:@selector(backgroundMethod:) withObject:@{@"userInfo" : userInfo, @"updateUI" : @(NO)}]; – user2134883 Mar 28 '13 at 06:08