iOS收到Push后播放聲音和震動


一、APNS

1.注冊


[cpp]
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert]; 

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert];
2.服務器推送(JAVA)


[java]
PushNotificationPayload payLoad =  PushNotificationPayload.fromJSON(message);  
              
        payLoad.addAlert("iphone推送測試 www.baidu.com"); // 消息內容   
              
        payLoad.addBadge(count); // iphone應用圖標上小紅圈上的數值   
              
        payLoad.addSound("default"); // 鈴音 默認  

PushNotificationPayload payLoad =  PushNotificationPayload.fromJSON(message);
            
        payLoad.addAlert("iphone推送測試 www.baidu.com"); // 消息內容
            
        payLoad.addBadge(count); // iphone應用圖標上小紅圈上的數值
            
        payLoad.addSound("default"); // 鈴音 默認
二、程序內

1.震動

添加系統框架:


[cpp]
#import <AudioToolbox/AudioToolbox.h> 

#import <AudioToolbox/AudioToolbox.h>
調用震動代碼:


[cpp]
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); 

AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
2.消息聲音

2.1 系統聲音


[cpp]
AudioServicesPlaySystemSound(1007); 

AudioServicesPlaySystemSound(1007);其中1007是系統聲音的編號,其他的可用編號:

iphone系統聲效

 

2.2 用戶音效


[cpp]
//音效文件路徑  
    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); 

//音效文件路徑
 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);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM