我的负载是否格式错误,无法在后台调用 didReceiveRemoteNotification?

Is my payload malformed to call didReceiveRemoteNotification in background?

根据关于 SO 的这些(以及更多)问题:

我发现,静默推送通知和方法

的主键

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


要在后台调用的是:负载,iOS 版本 > iOS 7,使用 "Remote notifications" 启用后台模式并在
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 中注册推送通知
方法。

我做了所有这些事情,但是上面提到的应该在后台调用的方法只在应用程序在前台时被调用。这就是我在 php:

中形成有效载荷的方式
$contents = json_encode(array(
            'aps'   => array(
                'content-available' => '1',
                'sound' => '',
                'alert' => '',
            ),
            'where' => array(
                'deviceType'    => array(
                '$in'   =>  array('ios', 'android'),
                ),
            ),
            'data'  => array(
                'title' => $this->subject,
                'msg'   => $this->message,
                'date'  => date('d.m.Y H:i', time() + (60 * 60 * 2)),
                'key'   => APPKEY,
                'ids'   => $ids,
            ),

        ));

这就是我在 Xcode 控制台中得到的,因为我能够在应用程序处于前台时 NSLog 有效负载:

{
    aps =     {
    };
    date = "21.10.2015 11:01";
    ids =     (
        259,
        257,
        256,
    );
    key = xpy3fq4t3wn9;
    msg = test11;
    title = aatest1;
}

我做错了什么?为什么 "content-available = 1" 不在 Xcode 控制台中?还是有其他原因导致 appDelegate 方法没有在后台调用?

我正在使用 iOS 8.1.3,解析为推送通知提供程序。

我可以通过尝试不同的有效负载组合来解决我的问题,最终得到了这个:

$contents = json_encode(array(

            'where' => array(
                'deviceType'    => array(
                '$in'   =>  array('ios', 'android'),
                ),
            ),
            'data'  => array(
                'title' => $this->subject,
                'msg'   => $this->message,
                'date'  => date('d.m.Y H:i', time() + (60 * 60 * 2)),
                'key'   => APPKEY,
                'ids'   => $ids,
                'aps'   => array(
                     'content-available'    => '1',
                     'sound'    => '',
                     'alert' => '',
                 ),
            ),

        ));

看起来 'aps' 必须在 'data' 数组中。现在正在后台调用应用程序委托方法,我可以在 Xcode 控制台中看到 "content-available = 1"。