仅当设备从锁定屏幕返回后,iOS推送通知才会触发

时间:2018-12-20 01:29:34

标签: ios objective-c push-notification

我正在处理推送通知,当网络波动时(例如,当应用程序正在运行并使用wi-fi时,我关闭并打开wi-fi路由器上的WAN连接),它会出现,静默推送通知(has_content = 1)不触发。但是,如果我锁定了手机(当应用程序仍在前台运行时)并通过按主屏幕按钮再次将其解锁,则应用程序会立即收到静默推送通知。

我正在使用iOS 12.0。并使用推梁作为服务提供商 这是示例代码:

   - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
      center.delegate = self;
      [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error)
       {
         if( !error )
         {
           [[UIApplication sharedApplication] registerForRemoteNotifications];  // required to get the app to do anything at all about push notifications
         }
         else
         {

         }
       }];
    }

    -(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{

  NSLog( @"Triggers only after a app comes back from device unlock %@", userInfo );
  }

0 个答案:

没有答案