//
// AppDelegate.swift
// H56580E2E
//
import UIKit
import UserNotifications //检查权限所需
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var destinatinoViewController = GuideViewController()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
//程序载入后执行
print("didFinishLaunchingWithOptions:程序载入")
//判断是否进入引导页
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let userdefault = UserDefaults.standard
//获取用户有没有进入引导页
let isopen_Guide = userdefault.bool(forKey: MyToole.userDefault_is_yindao)
if !isopen_Guide{
//没有进入过就进入引导页
let guideViewController = storyboard.instantiateViewController(withIdentifier: "GuideViewController") as! GuideViewController
self.window?.rootViewController = guideViewController
}
//权限检测
permissionsControl()
return true
}
//权限控制
func permissionsControl(){
UNUserNotificationCenter.current().getNotificationSettings {
settings in
//是否允许通知
switch settings.authorizationStatus {
case .authorized:
//允许
break
case .notDetermined:
//未确定
break
case .denied:
//不允许
self.alert_noNetwrok("你的通知权限未打开,请到设置中打开通知权限","提示")
break
}
//声音
switch settings.soundSetting{
case .enabled:
//开启
break
case .disabled:
//关闭
break
case .notSupported:
//不支持
//self.alert_noNetwrok("请开启您的声音","提示")
break
}
//应用图标标记
switch settings.badgeSetting{
case .enabled:
//开启
break
case .disabled:
//关闭
break
case .notSupported:
//不支持
//self.alert_noNetwrok("请允许图标标记","提示")
break
}
//在锁定屏幕上显示
switch settings.lockScreenSetting{
case .enabled:
//开启
break
case .disabled:
//关闭
break
case .notSupported:
//不支持
//self.alert_noNetwrok("请允许应用在锁屏时显示信息","提示")
break
}
//在历史记录中显示
switch settings.notificationCenterSetting{
case .enabled:
//开启
break
case .disabled:
//关闭
break
case .notSupported:
//不支持
break
}
//横幅显示
switch settings.alertSetting{
case .enabled:
//开启
break
case .disabled:
//关闭
break
case .notSupported:
//不支持
break
}
//显示预览
switch settings.showPreviewsSetting{
case .always:
//始终(默认
break
case .whenAuthenticated:
//解锁时
break
case .never:
//从不
break
}
}
//定位权限检测,申请
if CLLocationManager.authorizationStatus() != .denied{
print("拥有定位权限")
}else{
self.alert_noNetwrok("请开启您的定位权限", "提示")
}
}
func applicationWillResig
ios-swif-权限判断申请
最新推荐文章于 2024-07-09 17:37:16 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)