主要咱們收到訂單推送時,要設置聲音提示ui
首先必定要調用靜態庫#import <AudioToolbox/AudioToolbox.h>spa
設置代碼以下,在收到訂單推送的地方判斷orm
// iOS 10 Support,程序在前臺時string
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger)it
)completionHandler {io
// Requiredclass
NSDictionary * userInfo = notification.request.content.userInfo;import
if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]file
]) {request
//判斷是新訂單仍是退貨
NSString *str =[NSString stringWithFormat:@"%@",userInfo[@"aps"][@"alert"]];
NSLog(@"user-----%@",userInfo);
if ([str containsString:@"新訂單"]) {
//音效文件路徑
NSString *path = [[NSBundle mainBundle] pathForResource:@"haoyebao" ofType:@"wav"];
這裏是指你的音樂名字和文件類型
NSLog(@"path---%@",path);
//組裝並播放音效
SystemSoundID soundID;
NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)filePath, &soundID);
AudioServicesPlaySystemSound(soundID);
}else if([str containsString:@"退貨"]){
}else{
}
[JPUSHService handleRemoteNotification:userInfo];
}
completionHandler(UNNotificationPresentationOptionAlert); // 須要執 這個 法,選擇 是否提醒 戶,有Badge、Sound、Alert三種類型能夠選擇設置
}
2.若是要設置消息收到時顯示系統聲音,那麼就設置在收到消息的地方開啓聲音
//設置聲音,其中1312是系統聲音編號,能夠選擇你喜歡的
// AudioServicesPlaySystemSound(1312);