我的要求是在iPad上点击弹出通知消息,我从网络服务获取消息。我在一定的时间间隔后调用Web服务,并且只有当用户被通知然后我才必须显示通知。 我的代码不起作用,我想要弹出。我的代码如下:
- (void)scheduleNotificationWithInterval:(NSString *)Notificationmsg
{
[[UIApplication sharedApplication] cancelAllLocalNotifications];
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
if (localNotification == nil)
return;
localNotification.fireDate = [NSDate date];
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.alertBody = @"MyApp!";
localNotification.repeatInterval = nil;
localNotification.alertBody = [NSString stringWithFormat:NSLocalizedString(Notificationmsg, nil)];
localNotification.alertAction = NSLocalizedString(@"View Details", nil);
localNotification.applicationIconBadgeNumber = 1;
/*
NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:@"Object 1", @"Key 1", @"Object 2", @"Key 2", nil];
localNotification.userInfo = infoDict;*/
[[UIApplication sharedApplication] presentLocalNotificationNow:localNotification];
}
请帮帮我。
答案 0 :(得分:1)
试试这个:
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{
// I recieved a notification
}
将此方法放在Appdelegate类中。
答案 1 :(得分:0)
当您的火力本地通知和应用程序处于打开状态时,它将调用此方法,如果应用程序处于后台模式,它将显示通知,即您为应用程序设置的样式。
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive)
{
NSLog(@"lcoal:%@",[notification userInfo]);
UIAlertView *al=[[UIAlertView alloc]initWithTitle:@"Challenge gehaald!" message:@"Gefeliciteerd, je hebt deze bonus challenge succesvol afgerond." delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil];
[al show];
}
}