你好,歡迎來到IOS教程網

 Ios教程網 >> IOS訊息 >> 關於IOS >> IOS 新消息通知提示

IOS 新消息通知提示

編輯:關於IOS

一、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);

 

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved