How can I create iOS push notifications that don’t vibrate?

前端 未结 5 1913
终归单人心
终归单人心 2021-01-02 09:29

I know how to create silent push notifications (with playing a sound file that is silent). I would also like to send a push notification that doesn\'t vibrate phone.

相关标签:
5条回答
  • 2021-01-02 10:03
    [[UIApplication sharedApplication]registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge];
    

    Please try to register for remote notifications using above code applicationDidFinsihLaunching method of AppDelegate

    0 讨论(0)
  • 2021-01-02 10:06

    when you register for push notification don't ask for sound type (UIRemoteNotificationTypeSound)

    - (void)registerForRemoteNotificationTypes:(UIRemoteNotificationType)types
    

    you can test this by manually removing the sound permission in the notification settings

    0 讨论(0)
  • 2021-01-02 10:10

    I've faced with similiar issue. Vibration can be fixed by setting background fetch in project capabilities

    0 讨论(0)
  • 2021-01-02 10:17

    Omitting the sound key should do the trick:

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

    The docs state that "If the sound file doesn’t exist or default is specified as the value, the default alert sound is played.". What they don't say is that if you don't provide a sound key at all, no sound will be played. If no sound is played, the phone should not vibrate as well.

    0 讨论(0)
  • 2021-01-02 10:22

    I did it this way: server send a push to device with sound file name which is silent. That's it.

    Example:

    Incomming payload from server:

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

    And device handle it in 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);
    }
    
    0 讨论(0)
提交回复
热议问题