如何创建不振动的iOS推送通知?

Dix*_*ine 9 iphone objective-c push-notification ios

我知道如何创建静音推送通知(播放静音的声音文件).我还想发送一个不振动手机的推送通知.

当按照以下建议设置静音声音文件时,手机在锁定或应用程序未激活时仍会振动.

我的有效载荷仍然振动:

{
    aps =     {
        alert =         {
            "loc-key" = "SOME_KEY";
        };
        badge = 1;
        sound = "silence.caf";
    };
}
Run Code Online (Sandbox Code Playgroud)

这可能吗?

Tam*_*ese 12

省略声音键应该可以解决问题:

{"aps":{"alert":{"loc-key":"SOME_KEY"}, "badge":1}
Run Code Online (Sandbox Code Playgroud)

文档声明"如果声音文件不存在或默认值被指定为值,则播放默认警报声音.".他们没有说的是,如果你根本不提供声音键,就不会播放声音.如果没有播放声音,手机也不应该振动.


Ida*_*she 0

我是这样做的:服务器向设备发送一个带有声音文件名的推送,该设备是无声的。就是这样。

例子:

从服务器传入的有效负载:

{ aps = { "content-available" = 1; sound="silence.mp3" }; data-id = 1234; }
Run Code Online (Sandbox Code Playgroud)

设备在以下位置处理它AppDelegate

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    NSInteger data_id= [userInfo[@"data-id"] integerValue];
    NSLog(@"Data-id: %i", data_id);
    //
    //  code...
    //
    // UIBackgroundFetchResultNoData/UIBackgroundFetchResultFailed/UIBackgroundFetchResultNewData
    completionHandler(UIBackgroundFetchResultNewData);
}
Run Code Online (Sandbox Code Playgroud)