- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试了很多在应用程序处于前台时获得修改通知....通过创建 Notification Service Extensions
在后台并杀死成功修改但在前台仅在警报正文中获取原始有效载荷而不是在通知中。
这里在 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"]);
}
}}
最佳答案
实现 UNUserNotificationCenterDelegate
委托(delegate)方法以在应用程序处于前台时获取通知(顶部托盘)。但它只适用于 IOS 10。
在您的 didFinishLaunchingWithOptions
方法中,像这样设置 UNUserNotificationCenterDelegate
委托(delegate)。
[UNUserNotificationCenter currentNotificationCenter].delegate = self;
实现委托(delegate)方法...
//Called when a notification is delivered to a foreground app.
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler{
completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);
}
//Called to let your app know which action was selected by the user for a given notification.
-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler{
completionHandler();
}
注意
如果您的应用程序开发目标小于 IOS10,则使用它来设置委托(delegate)。
#if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
// For iOS 10 display notification (sent via APNS)
[UNUserNotificationCenter currentNotificationCenter].delegate = self;
#endif
关于ios - 应用程序在前台 iOS 时未在通知托盘(顶部)中获取推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44322319/
我想在同一运行时间内拥有多种货币。默认节点模板中插入了 Balances 托盘,但如果我正确的话,它只能处理一种货币。 如何多次重复使用托盘? 最佳答案 Pallet 可以实例化,这样您就可以在同一运
我正在尝试使用一段代码打开和关闭计算机的 CD 托盘。我一直在使用 MCI 命令,并将 winmm.lib 包含在我的项目配置的附加依赖项中。我还包含了 windows.h 和 mmsystem.h。
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
我正在使用electron-react-boilerplate开发 Electron 应用程序(使用electron-builder打包应用程序)。 我想创建托盘,但是它需要图标路径或 native
有没有办法选择在 Java 中打印时使用哪个出纸盒/托盘?有一个属性 MediaTray 允许您选择输入托盘,但我找不到允许您选择输出的属性。 最佳答案 除了MediaTray , 有一个 Desti
我是一名优秀的程序员,十分优秀!