一、APNS
1.註冊
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert];
2.伺服器推送(JAVA)
PushNotificationPayload payLoad = PushNotificationPayload.fromJSON(message); payLoad.addAlert("iphone推送測試 www.baidu.com"); // 訊息內容 payLoad.addBadge(count); // iphone應用表徵圖上小紅圈上的數值 payLoad.addSound("default"); // 鈴音 預設
二、程式內
1.震動
添加系統架構:
#import <AudioToolbox/AudioToolbox.h>
調用震動代碼:
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
2.訊息聲音
2.1 系統聲音
AudioServicesPlaySystemSound(1007);
其中1007是系統聲音的編號,其他的可用編號:
iphone系統聲效
2.2 使用者音效
//音效檔案路徑NSString *path = [[NSBundle mainBundle] pathForResource:@"message" ofType:@"wav"];//組裝並播放音效SystemSoundID soundID;NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];AudioServicesCreateSystemSoundID((__bridge CFURLRef)filePath, &soundID);AudioServicesPlaySystemSound(soundID); //聲音停止 AudioServicesDisposeSystemSoundID(soundID);