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

6

9

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.

When setting silent sound file as suggested below phone still vibrates when it is locked or when the app is not active.

My payload that still vibrates:

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

Is this possible?

Vise answered 20/5, 2014 at 7:0 Comment(6)
sound = ""; Try this one :)Fictionist
@DavidR. He was asking about "send a push notification that doesn't vibrate phone."Shoveler
Yes i need to know how to turn off vibration.Vise
yeah, i can understand his question. Same thing i want to told just put silence sound. if sound is there so device is not vibratingFictionist
sound="" is not working, phone still vibrates.Vise
See my answer below. You have to omit the entire sound key, then no sound will be played. Setting sound="" is interpreted as a non-existing file, which will lead to the default sound being played.Nonrigid
N
12

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.

Nonrigid answered 31/5, 2014 at 10:24 Comment(5)
Confirming this worked for me also. I had a similar issue, where I registered for Sounds when registering for pushNotifications, but not including a 'sound' key in the apns payload. When a notification came, there was no vibrations. When we included the 'sound' key, but with a blank string, the notification vibrated the phone / apple watch. Hope this helps anyone having this similar problem!Curtis
it doesn't work anymore I suppose. I sent the alert body only like this {"aps":{"alert":{"loc-key":"SOME_KEY"}} and vibration occurred anyway even if there was no "sound" key specified.Duteous
@Duteous That's sad news. On which version of iOS have you got that result?Nonrigid
@TammoFreese I'm currently testing on iOS 8.4Duteous
@Curtis how can i set for No vibrate only get sound ? i want only sound no vibrate....Astaire
L
0

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);
}
Lipson answered 20/5, 2014 at 7:11 Comment(1)
It still vibrates (ios 7.1) when phone is locked and therefore - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions is executed.Vise
H
0

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

Hutch answered 29/5, 2014 at 20:31 Comment(1)
But what if i wanted to have some types of notifications with sound and some without sound and vibration?Vise
K
0
[[UIApplication sharedApplication]registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge];

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

Kassala answered 2/6, 2014 at 9:9 Comment(0)
D
0

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

Doctor answered 6/7, 2016 at 12:37 Comment(0)
A
0

I have to add in AppDelegate :

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    NotificationCenter.default.post(name: Notification.Name.init("didReceiveRemoteNotification"), object: completionHandler, userInfo: userInfo)
}

And check "Remote notifications" in the Capabilities "Background Modes".

Then I send a notification with only the data :

device.send_message(
                    messaging.Message(
                        data = data,
                ), app = FCMApp)
Ashling answered 25/7, 2024 at 17:49 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.