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

我知道如何创build静音推送通知(播放无声的声音文件)。 我还想发送不振动手机的推送通知。

如下所示设置静音文件时,手机在locking或应用程序未处于活动状态时仍然会振动。

我的有效载荷仍然振动:

{ aps = { alert = { "loc-key" = "SOME_KEY"; }; badge = 1; sound = "silence.caf"; }; } 

这可能吗?

省略声音键应该做的伎俩:

 {"aps":{"alert":{"loc-key":"SOME_KEY"}, "badge":1} 

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

我这样做:服务器发送一个推送到声音文件名是沉默的设备。 而已。

例:

从服务器接收有效载荷:

 { aps = { "content-available" = 1; sound="silence.mp3" }; data-id = 1234; } 

而设备在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); } 

当你注册推送通知时不要求声音types( UIRemoteNotificationTypeSound

 - (void)registerForRemoteNotificationTypes:(UIRemoteNotificationType)types 

您可以通过手动删除通知设置中的声音权限来进行testing

 [[UIApplication sharedApplication]registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge]; 

请尝试使用AppDelegate的上面的代码applicationDidFinsihLaunching方法注册远程通知

我遇到了类似的问题。 可以通过在项目function中设置背景获取来修复振动