我正在开发一个应用程序,我正在使用静默推送通知来发送一些数据。当应用程序处于活动状态时推送工作正常,但如果我刷出应用程序或它处于非活动状态,我的应用程序没有收到推送通知。我在功能下启用了后台模式下的推送通知,并在 info.plist 中添加了所需的后台模式键
这是我与推送一起发送的示例数据
{
"aps": {
"content-available": 1
},
"yourdatakey":{data}
}
我应该怎么做才能解决这个问题??.. iOS 应用程序可以在非活动模式下接收静默推送通知吗?
-(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void(^)(UIBackgroundFetchResult))completionHandler
{
if( SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO( @"10.0" ) )
{
NSLog( @"iOS version >= 10. Let NotificationCenter handle this one." );
return;
}
NSLog( @"HANDLE PUSH, didReceiveRemoteNotification: %@", userInfo );
if( [UIApplication sharedApplication].applicationState == UIApplicationStateInactive )
{
NSLog( @"INACTIVE" );
completionHandler( UIBackgroundFetchResultNewData );
}
else if( [UIApplication sharedApplication].applicationState == UIApplicationStateBackground )
{
NSLog( @"BACKGROUND" );
completionHandler( UIBackgroundFetchResultNewData );
}
else
{
NSLog( @"FOREGROUND" );
completionHandler( UIBackgroundFetchResultNewData );
}
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
{
NSLog( @"Handle push from foreground" );
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)())completionHandler
{
NSLog( @"Handle push from background or closed" );
}
Push 在我的应用程序中起着至关重要的作用,并且不希望有任何延迟。我应该怎么做才能立即收到推送??...