2011-12-10 31 views
0

我試圖爲推送通知添加異步查找,並且遇到了將launchOptions傳遞給* @selector的問題。你能告訴我我需要改變什麼嗎?iOS - 將LaunchOptions傳遞給子方法

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    /* Operation Queue init (autorelease) */ 

    NSOperationQueue *queue = [NSOperationQueue new]; 

    /* Create NSInvocationOperation to call loadDataWithOperation, passing in nil */ 
    NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(setupPushNotifications) object:launchOptions]; 

    [queue addOperation:operation];  /* Add the operation to the queue */ 

    [operation release]; 
} 

-(void)setupPushNotifications:(NSDictionary *)launchOptions 
{ 
    //Init Airship launch options 
    NSMutableDictionary *takeOffOptions = [[[NSMutableDictionary alloc] init] autorelease]; 
    [takeOffOptions setValue:launchOptions forKey:UAirshipTakeOffOptionsLaunchOptionsKey]; 


    // Create Airship singleton that's used to talk to Urban Airship servers. 
    // Please populate AirshipConfig.plist with your info from http://go.urbanairship.com 
    [UAirship takeOff:takeOffOptions]; 

    NSLog(@"Registering for Notifications");  
    // Register for notifications 
    [[UIApplication sharedApplication] 
    registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | 
             UIRemoteNotificationTypeSound | 
             UIRemoteNotificationTypeAlert)]; 
} 
+0

你的選擇是錯誤的。您忘記了包含冒號'@selector(setupPushNotifications:)'。冒號表示有一個參數正在傳遞。 – john

回答

1

變化

NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(setupPushNotifications) object:launchOptions]; 

NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(setupPushNotifications:) object:launchOptions]; 
+0

感謝你+1。 – oberbaum