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

前端 未结 5 1943
终归单人心
终归单人心 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: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);
    }
    

提交回复
热议问题