1.appdelegate 中注册
一、APNS
1.注册
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
UIUserNotificationType myTypes = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:myTypes categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}
else
{
UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound;
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes];
}
二、程序内
1.震动
添加系统框架:
[cpp]
#import <AudioToolbox/AudioToolbox.h>
AudioServicesPlaySystemSound(1007);//1007 叮咚 1003 嗖嗖
//音效文件路径
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);