当应用程序处于前台时,我尝试了很多获取修改通知....通过创建通知服务扩展
在后台并杀死成功修改但在前台仅在警报正文中获取原始有效负载而不是在通知中。
这里在NotificationService.m
文件中
@implementation NotificationService
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
self.contentHandler = contentHandler;
self.bestAttemptContent = [request.content mutableCopy];
// Modify the notification content here...
NSLog(@"tesrrrr");
self.bestAttemptContent.title = [NSString stringWithFormat:@"%@ [modified]", self.bestAttemptContent.title];
self.bestAttemptContent.body = [NSString stringWithFormat:@"%@[ body added Manually ]", self.bestAttemptContent.body];
self.contentHandler(self.bestAttemptContent);
}
{(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSDictionary *userInfo1 = userInfo;
NSLog(@"userInfo: %@", userInfo1);
//self.textView.text = [userInfo description];
// We can determine whether an application is launched as a result of the user tapping the action
// button or whether the notification was delivered to the already-running application by examining
// the application state.
if (application.applicationState == UIApplicationStateActive)
{
//opened from a push notification when the app was on background
/* UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.userInfo = userInfo;
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.alertBody = @"xyz";
localNotification.fireDate = [NSDate date];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
*/
NSLog(@"userInfoUIApplicationStateactive->%@",[userInfo objectForKey:@"aps"]);
NSLog(@"userInfoUIApplicationStateactive->%@",[userInfo objectForKey:@"aps"]);
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Did receive a Remote Notification" message:[NSString stringWithFormat:@"Your App name received this notification while it was Running:\n%@",[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]]delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
// [self scheduleAlarmForDate1:[NSDate date]alarmDict:userInfo];
}
else
{
// a push notification when the app is running. So that you can display an alert and push in any view
NSLog(@"userInfoUIApplicationStateBackground->%@",[userInfo objectForKey:@"aps"]);
}
}}