我希望在挂起模式下调用didupdatelocation方法时推送通知。
{{1}}
在前台它工作正常但在暂停模式下它不起作用。
答案 0 :(得分:0)
执行以下操作
的AppDelegate
1.didFinishLaunchingWithOptions
if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
{
// iOS 8 Notifications
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[application registerForRemoteNotifications];
}
else
{
// iOS < 8 Notifications
[application registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
}
2.添加此方法
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive)
{
UIAlertView *notificationAlert = [[UIAlertView alloc] initWithTitle:@"Notification"message: notification.alertBody delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[notificationAlert show];
}
[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadData" object:self];
application.applicationIconBadgeNumber = 0;
}
3.Call通知,无论您需要什么
UILocalNotification *localNotification = [[UILocalNotification alloc]init];
localNotification.fireDate = date;
localNotification.alertBody = @"Playing aiff sound";
localNotification.alertAction = titleTextField.text;
localNotification.soundName = @"b";
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication]applicationIconBadgeNumber]+1;
[[UIApplication sharedApplication]scheduleLocalNotification:localNotification];
我希望这会对你有帮助..