APNs Payload 中 aps.sound 缺失或為 "default" 時,系統播放內置三聲提示音,無需客戶端代碼參與。
"sound": "custom.caf"。custom.caf(≤30s,支持格式:caf/aiff/wav)。AudioServicesPlaySystemSound 播放。若需在前台自行控制播放(如混音、振動配合),可在 didReceiveRemoteNotification 中:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSString *soundName = userInfo[@"aps"][@"sound"];
if (soundName && ![soundName isEqualToString:@"default"]) {
NSURL *url = [[NSBundle mainBundle] URLForResource:[soundName stringByDeletingPathExtension] withExtension:[soundName pathExtension]];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((__bridge CFURLRef)url, &soundID);
AudioServicesPlaySystemSound(soundID);
}
}
AudioServicesPlaySystemSound 可能仍可聽見(取決於類別)。