iOS - 将LaunchOptions传递给子方法

时间:2011-12-10 20:33:57

标签: iphone ios uilocalnotification

我试图为推送通知添加异步查找,并且我在将launchOptions传递给* @selector时遇到问题。你能告诉我我需要改变什么吗?

- (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)];
}

1 个答案:

答案 0 :(得分:1)

变化

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

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