DidFinishLaunching中的UILocalNotification对象总是为零?

时间:2012-04-10 07:14:04

标签: iphone ios uilocalnotification

我正在为指定日期创建本地通知,如下所示

UILocalNotification *localNotify = [[UILocalNotification alloc]init];
        [localNotify setFireDate:notificationDate];
        [localNotify setTimeZone:[NSTimeZone localTimeZone]];
        [localNotify setAlertBody:@"Daily Items Reminder"];
        //[localNotify setAlertLaunchImage:@"blank_Btn"];
        [localNotify setAlertAction:@"View"];
        [localNotify setSoundName:UILocalNotificationDefaultSoundName];
        [localNotify setApplicationIconBadgeNumber:1];
        [localNotify setRepeatInterval:NSDayCalendarUnit];
        NSDictionary *userDict = [NSDictionary dictionaryWithObject:@"dict"
                                                             forKey:@"key"];
        localNotify.userInfo = userDict;
        [[UIApplication sharedApplication] scheduleLocalNotification:localNotify];
        [localNotify release];

在我的 ApplicationDidFinishLaunching 中,我为 UILocalNotification 创建一个对象,如下所示

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];

UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];

if (notification)
{
    NSInteger badgeNumber =  notification.applicationIconBadgeNumber;

    if (badgeNumber < 0)
    {
        notification.applicationIconBadgeNumber = 0;
    }
    else
    {
        notification.applicationIconBadgeNumber = badgeNumber - 1;
    }

    [self showAlertMessage:@"didFinishLaunchingWithOptions" withButtons:eOk forDelegate:self];
    // open screen
}
}

本地通知出现后,点击查看按钮,应用程序启动,现在 launchOption 应该通过密钥返回 localnotification对象但是它总是返回nil,因为alertview没有被调用?? ??我可能做错了什么?

0 个答案:

没有答案