iOS9以後創建UIAlertView時會出現警告,蘋果對UIAlertView進行了優化,添加了UIAlertController,下面是UIAlertController的實現方法:
1、創建一個UIAlertController 並設置標題和提示信息
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"GPS不可用是否去設置"preferredStyle:UIAlertControllerStyleAlert];
2、創建一個 UIAlertAction對象,塊裏面可以實現回調方法 相當於之前的確定和取消按鈕
kkw'yi UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"去設置" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//跳轉到系統設置頁面
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
3、添加UIAlertAction對象到UIAlertController中去
[alertController addAction:cancelAction];
[alertController addAction:okAction];
4、跳轉到alertController中去就實現了這個方法
[self presentViewController:alertController animated:YES completion:nil];
做完以上步驟就大功告成了~