Внедрите следующий код в AppDelegate для получения уведомлений, когда приложение находится на переднем плане.
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.alert, .sound])
}
Убедитесь, что AppDelegate соответствует протоколу UNUserNotificationCenterDelegate
и задайте UNUserNotificationCenter.current().delegate = self
в методе didFinishLaunchingWithOptions
.
Пожалуйста, найдите do c здесь .
РЕДАКТИРОВАТЬ 2:
#import <Firebase.h>
#import "AppDelegate.h"
#import <GoogleMaps/GoogleMaps.h>
#import <UserNotifications/UserNotifications.h>
@interface NFAppDelegate () <UNUserNotificationCenterDelegate>
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[FIRApp configure];
[GMSServices provideAPIKey:@"AIzcasdsr4ZdsdsA7BIxJxb6g3XE"];
[UNUserNotificationCenter currentNotificationCenter].delegate = self;
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[super applicationWillEnterForeground:application];
}
#pragma mark - Handling URLs
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
return [super application:app openURL:url options:options];
}
#pragma mark - Notifications
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)token
{
[super application:application didRegisterForRemoteNotificationsWithDeviceToken:token];
}
#pragma mark - UNNotificationCenterDelegate
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
completionHandler(UNNotificationPresentationOptionAlert|UNNotificationPresentationOptionSound);
}
@end