iOS系統(tǒng)可支持本地通知和遠(yuǎn)程通知,一個(gè)通知在客戶端收到的時(shí)候可能是一個(gè)通知窗體,可能會(huì)播放一段通知聲音,還有可能在程序圖標(biāo)上增加一個(gè)數(shù)字,還有可能三者皆有。
1、UIKeyboardWillShowNotification-將要彈出鍵盤
2、UIKeyboardDidShowNotification-顯示鍵盤
3、UIKeyboardWillHideNotification-將要隱藏鍵盤
4、UIKeyboardDidHideNotification-鍵盤已經(jīng)隱藏
5、UIKeyboardWillChangeFrameNotification-鍵盤將要改變frame
6、UIKeyboardDidChangeFrameNotification-鍵盤已經(jīng)改變frame
1、UIWindowDidBecomeVisibleNotification-窗口可見
2、UIWindowDidBecomeHiddenNotification-窗口隱藏
3、UIWindowDidBecomeKeyNotification
4、UIWindowDidResignKeyNotification
1、UIApplicationDidBecomeActiveNotification-程序從后臺(tái)激活
2、UIApplicationDidChangeStatusBarFrameNotification-狀態(tài)欄frame改變
3、UIApplicationDidChangeStatusBarOrientationNotification-狀態(tài)欄方向改變
4、UIApplicationDidEnterBackgroundNotification-進(jìn)入后臺(tái)
5、UIApplicationDidFinishLaunchingNotification-程序加載完成
6、UIApplicationDidReceiveMemoryWarningNotification-內(nèi)存警告
7、UIApplicationProtectedDataDidBecomeAvailable
8、UIApplicationProtectedDataWillBecomeUnavailable
9、UIApplicationSignificantTimeChangeNotification重要的時(shí)間變化(新的一天開始或時(shí)區(qū)變化)
10、UIApplicationWillChangeStatusBarOrientationNotification-將要改變狀態(tài)欄方向
11、UIApplicationWillChangeStatusBarFrameNotification-將要改變狀態(tài)欄frame
12、UIApplicationWillEnterForegroundNotification
13、UIApplicationWillResignActiveNotification
14、UIApplicationWillTerminateNotification
1、UIDeviceBatteryLevelDidChangeNotification//電池電量
2、UIDeviceBatteryStateDidChangeNotification//電池狀態(tài)
3、UIDeviceOrientationDidChangeNotification//方向
4、UIDeviceProximityStateDidChangeNotification//近距離傳感器
1、MPMediaLibraryDidChangeNotification
2、MPMusicPlayerControllerPlaybackStateDidChangeNotification
3、MPMusicPlayerControllerNowPlayingItemDidChangeNotification
4、MPMusicPlayerControllerVolumeDidChangeNotification
1、NSUserDefaultsDidChangeNotification用戶默認(rèn)設(shè)置變化
2??NSCurrentLocaleDidChangeNotification本地化語言變化
第一個(gè)知識(shí)點(diǎn):準(zhǔn)備個(gè)人定制音頻作為提示音,
請(qǐng)注意下面四個(gè)小問題-----
1,
系統(tǒng)能播放的四種音頻數(shù)據(jù)格式
Linear PCM
MA4 (IMA/ADPCM)
μLaw
aLaw
對(duì)應(yīng)的后綴名可以是aiff, wav, or caf file. Then,
2, 可以用afconvert來轉(zhuǎn)換音頻,例如把16位的線性PCM系統(tǒng)音頻格式文件 Submarine.aiff 轉(zhuǎn)換成IMA4音頻,存為.CAF文件。
在終端執(zhí)行即可
afconvert /System/Library/Sounds/Submarine.aiff ~/Desktop/sub.caf -d ima4 -f caff -v
3, 如何確定音頻格式呢。
打開QuickTime Player-> Movie menu->Show Movie Inspector
4, 個(gè)人定制音頻必須是30s以下。否則就播放默認(rèn)的聲音了。
第二個(gè)知識(shí)點(diǎn):預(yù)定一個(gè)Local Notification
需要了解下面5個(gè)步驟
1, Allocate 和 initialize 一個(gè) UILocalNotification對(duì)象。
2, fireDate屬性賦值
3, 設(shè)置別的幾個(gè)體型要素 提示框,提示音,圖標(biāo)上的提示數(shù)字。也可以帶別的個(gè)性化數(shù)據(jù):通過userInfo帶出去。
4, 然后Schedule這個(gè)通知。通過UIApplication.scheduleLocalNotification來預(yù)定執(zhí)行或者立馬執(zhí)行presentLocalNotificationNow:
5, 也可以取消這個(gè)通知。用這個(gè)方法:cancelLocalNotification和cancelAllLocalNotifications這個(gè)方法
以下為系統(tǒng)通知應(yīng)用,在鍵盤彈出時(shí),使鍵盤不會(huì)覆蓋textField
{
UITextField*tempTF;
}
@end
@implementationViewController
- (void)viewDidLoad {
[superviewDidLoad];
//注冊(cè)viewController為監(jiān)聽者,并向通知中心發(fā)送信息
[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(keyboardShow:)name:UIKeyboardWillShowNotificationobject:nil];
[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(keyboardHidden:)name:UIKeyboardWillHideNotificationobject:nil];
}
#pragma mark ----實(shí)現(xiàn)鍵盤彈出的方法----
//實(shí)現(xiàn)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);
}
}
//實(shí)現(xiàn)keyboardHidden方法
-(void)keyboardHidden:(NSNotification*)sender{
CGFloatscreen_height = [[UIScreenmainScreen]bounds].size.height;
CGFloatscreen_width = [[UIScreenmainScreen]bounds].size.width;
//View恢復(fù)原位置
self.view.frame=CGRectMake(0,0, screen_width, screen_height);
}
#pragma mark ----實(shí)現(xiàn)textField的代理方法----
-(BOOL)textFieldShouldBeginEditing:(UITextField*)textField{
//將textField設(shè)置為當(dāng)前tempTF
tempTF=textField;
returnYES;
}
//按return鍵盤消失
-(BOOL)textFieldShouldReturn:(UITextField*)textField{
return[textFieldresignFirstResponder];
}