相关疑难解决方法(0)

当应用程序在前景Swift 3时获取本地通知

显然,ios10现在可以实现这一点:

optional func userNotificationCenter(_ center: UNUserNotificationCenter, 
                 willPresent notification: UNNotification, 
  withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void)
Run Code Online (Sandbox Code Playgroud)

这个答案基本上说明了做这件事所需的工具:

当您的应用程序处于打开状态且位于前台时显示库存iOS通知横幅?

我只是不太了解如何将它们放在一起.

我不知道这有多重要,但我无法保留可选的func,xcode要我将其切换为私有.

我正试图展示徽章,文档提供

static var badge: UNNotificationPresentationOptions { get }
Run Code Online (Sandbox Code Playgroud)

这里很少丢失.

然后我假设我想要排除某个视图控制器获取这些徽章并且我没有使用导航控制器这个代码我发现它会起作用吗?:var窗口:UIWindow?

if let viewControllers = window?.rootViewController?.childViewControllers {
for viewController in viewControllers {
    if viewController.isKindOfClass(MyViewControllerClass) {
        print("Found it!!!")
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

ios uilocalnotification swift swift3 unusernotificationcenter

35
推荐指数
4
解决办法
4万
查看次数

iOS 10,当app在前台时本地通知显示?

我想在应用程序处于forground时显示通知.下面是我为新的usernotificationdelegate方法所做的代码.

在app委托中:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.0")) {

        //iOS 10 handling
        UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
        center.delegate = self;
        [center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert) completionHandler:^(BOOL granted, NSError * _Nullable error) {
          if (!error) {
                 NSLog(@"request authorization succeeded!");
          } }];
     } 
}

#pragma mark - User notification delegate
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {

    NSLog(@"willPresentNotification");
    NSLog(@"%@", notification.request.content.userInfo);
    completionHandler (UNNotificationPresentationOptionAlert);
}
Run Code Online (Sandbox Code Playgroud)

这是我触发本地通知的方法

-(void) fireLocalNotification:(NSString *) message
{

    NSLog(@"fire Local Notification");
    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.0")) {

        //Notification Content …
Run Code Online (Sandbox Code Playgroud)

objective-c ios uilocalnotification unusernotificationcenter

1
推荐指数
1
解决办法
5097
查看次数