iOS系统可支持本地通知和远程通知,一个通知在客户端收到的时候可能是一个通知窗体,可能会播放一段通知声音,还有可能在程序图标上增加一个数字,还有可能三者皆有。
一、键盘
1、UIKeyboardWillShowNotification-将要弹出键盘
2、UIKeyboardDidShowNotification-显示键盘
3、UIKeyboardWillHideNotification-将要隐藏键盘
4、UIKeyboardDidHideNotification-键盘已经隐藏
5、UIKeyboardWillChangeFrameNotification-键盘将要改变frame
6、UIKeyboardDidChangeFrameNotification-键盘已经改变frame
二、窗口
1、UIWindowDidBecomeVisibleNotification-窗口可见
2、UIWindowDidBecomeHiddenNotification-窗口隐藏
3、UIWindowDidBecomeKeyNotification
4、UIWindowDidResignKeyNotification
三、程序消息
1、UIApplicationDidBecomeActiveNotification-程序从后台激活
2、UIApplicationDidChangeStatusBarFrameNotification-状态栏frame改变
3、UIApplicationDidChangeStatusBarOrientationNotification-状态栏方向改变
4、UIApplicationDidEnterBackgroundNotification-进入后台
5、UIApplicationDidFinishLaunchingNotification-程序加载完成
6、UIApplicationDidReceiveMemoryWarningNotification-内存警告
7、UIApplicationProtectedDataDidBecomeAvailable
8、UIApplicationProtectedDataWillBecomeUnavailable
9、UIApplicationSignificantTimeChangeNotification重要的时间变化(新的一天开始或时区变化)
10、UIApplicationWillChangeStatusBarOrientationNotification-将要改变状态栏方向
11、UIApplicationWillChangeStatusBarFrameNotification-将要改变状态栏frame
12、UIApplicationWillEnterForegroundNotification
13、UIApplicationWillResignActiveNotification
14、UIApplicationWillTerminateNotification
四、电池、方向、传感器
1、UIDeviceBatteryLevelDidChangeNotification//电池电量
2、UIDeviceBatteryStateDidChangeNotification//电池状态
3、UIDeviceOrientationDidChangeNotification//方向
4、UIDeviceProximityStateDidChangeNotification//近距离传感器
五、音视频
1、MPMediaLibraryDidChangeNotification
2、MPMusicPlayerControllerPlaybackStateDidChangeNotification
3、MPMusicPlayerControllerNowPlayingItemDidChangeNotification
4、MPMusicPlayerControllerVolumeDidChangeNotification
六、其他
1、NSUserDefaultsDidChangeNotification用户默认设置变化
2 NSCurrentLocaleDidChangeNotification本地化语言变化
第一个知识点:准备个人定制音频作为提示音,
请注意下面四个小问题-----
1,
系统能播放的四种音频数据格式
Linear PCM
MA4 (IMA/ADPCM)
µLaw
aLaw
对应的后缀名可以是aiff, wav, or caf file. Then,
2, 可以用afconvert来转换音频,例如把16位的线性PCM系统音频格式文件 Submarine.aiff 转换成IMA4音频,存为.CAF文件。
在终端执行即可
afconvert /System/Library/Sounds/Submarine.aiff ~/Desktop/sub.caf -d ima4 -f caff -v
3, 如何确定音频格式呢。
打开QuickTime Player-> Movie menu->Show Movie Inspector
4, 个人定制音频必须是30s以下。否则就播放默认的声音了。
第二个知识点:预定一个Local Notification
需要了解下面5个步骤
1, Allocate 和 initialize 一个 UILocalNotification对象。
2, fireDate属性赋值
3, 设置别的几个体型要素 提示框,提示音,图标上的提示数字。也可以带别的个性化数据:通过userInfo带出去。
4, 然后Schedule这个通知。通过UIApplication.scheduleLocalNotification来预定执行或者立马执行presentLocalNotificationNow:
5, 也可以取消这个通知。用这个方法:cancelLocalNotification和cancelAllLocalNotifications这个方法
以下为系统通知应用,在键盘弹出时,使键盘不会覆盖textField
{
UITextField*tempTF;
}
@end
@implementationViewController
- (void)viewDidLoad {
[superviewDidLoad];
//注册viewController为监听者,并向通知中心发送信息
[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(keyboardShow:)name:UIKeyboardWillShowNotificationobject:nil];
[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(keyboardHidden:)name:UIKeyboardWillHideNotificationobject:nil];
}
#pragma mark ----实现键盘弹出的方法----
//实现keyboardShow方法
-(void)keyboardShow:(NSNotification*)sender{
//打印useInfo获取键盘尺寸
NSLog(@"%@",sender.userInfo);
/*
UIKeyboardAnimationCurveUserInfoKey = 7;
UIKeyboardAnimationDurationUserInfoKey = "0.25";
UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {320, 253}}";
UIKeyboardCenterBeginUserInfoKey = "NSPoint: {160, 694.5}";
UIKeyboardCenterEndUserInfoKey = "NSPoint: {160, 441.5}";
UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 568}, {320, 253}}";
UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 315}, {320, 253}}";
UIKeyboardIsLocalUserInfoKey = 1;
*/
NSValue*rect =sender.userInfo[UIKeyboardFrameEndUserInfoKey];
//获取键盘高度
CGFloatkeyboardHeight= [rectCGRectValue].size.height;
//获取屏幕尺寸
CGFloatscreen_height= [[UIScreenmainScreen]bounds].size.height;
CGFloatscreen_width = [[UIScreenmainScreen]bounds].size.width;
CGFloatresult = screen_height - keyboardHeight;
//判断键盘是否挡住textField
if(result
//改变view的位置
self.view.frame=CGRectMake(0, result-tempTF.frame.origin.y-tempTF.frame.size.height,screen_width, screen_height);
}
}
//实现keyboardHidden方法
-(void)keyboardHidden:(NSNotification*)sender{
CGFloatscreen_height = [[UIScreenmainScreen]bounds].size.height;
CGFloatscreen_width = [[UIScreenmainScreen]bounds].size.width;
//View恢复原位置
self.view.frame=CGRectMake(0,0, screen_width, screen_height);
}
#pragma mark ----实现textField的代理方法----
-(BOOL)textFieldShouldBeginEditing:(UITextField*)textField{
//将textField设置为当前tempTF
tempTF=textField;
returnYES;
}
//按return键盘消失
-(BOOL)textFieldShouldReturn:(UITextField*)textField{
return[textFieldresignFirstResponder];
}