0

AppDelegate.m

- (void)applicationWillEnterForeground:(UIApplication *)application
{

application.applicationIconBadgeNumber = 0;
}

-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
application.applicationIconBadgeNumber = 0;
NSString *reminderText = [notification.userInfo objectForKey:kRemindMeNotificationDataKey];
[self.settings showReminderAlert:reminderText];
NSLog(@"Application REcieved Local Notification");
}

ViewController.m

-(void)showReminderAlert:(NSString *)text{
NSLog(@"Alert Called");
UIAlertView *reminderAlert = [[UIAlertView alloc]initWithTitle:@"Alert" message:text delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[reminderAlert show];
[reminderAlert release];
}

我希望我的应用程序在用户重新进入application.app didReceiveLocalNotification正在调用但未调用 Alert 方法时显示警报。

4

1 回答 1

1

showReminderAlert:在另一个视图控制器中对吗?可能是对象 self.settings(该视图控制器的对象)在重新打开应用程序时获得释放。在 appDelegate 本身中尝试警报

 -(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Alarm" message:message delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
            [alert show];
            [alert release];
}
于 2013-02-20T07:26:34.123 回答