【发布时间】:2012-04-29 05:30:52
【问题描述】:
我有一个应用程序注册位置更新、运行测试,有时当我在应用程序处于后台时进入某个区域时,我会收到带有声音的警报通知。有时我只在通知中心看到通知,并没有收到任何声音和警报... 怎样做才能始终收到声音和警报通知?
这就是我的看法
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.fireDate = nil;
localNotif.hasAction = YES;
localNotif.alertBody = fbName;
localNotif.alertAction = @"View";
localNotif.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication]presentLocalNotificationNow:localNotif];
这是应用委托
- (void)application:(UIApplication *)application didReceiveLocalNotification (UILocalNotification *)notification
{
if (notification)
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Alert"
message:notification.alertBody
delegate:self cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
facebook = [[Facebook alloc] initWithAppId:kAppId andDelegate:self];
UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (notification)
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Alert"
message:notification.alertBody
delegate:self cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
return YES;
}
【问题讨论】:
-
我不认为这完全一样,因为它在某些情况下有效,它似乎与我在后台的时间有关,它围绕状态当应用程序在后台并且 UILocalNotification 行为似乎不一致时,有人会遇到这种情况吗?
标签: ios uialertview uilocalnotification