在app初次運行時會提醒用戶是否開啟通知,從而實現(xiàn)消息推送功能。如果用戶未打開消息通知則我們需要定時提醒用戶開啟。
我們可以通過下面這個方法查看通知設置type。
[[UIApplicationsharedApplication]enabledRemoteNotificationTypes] //iOS8.0
[[UIApplicationsharedApplication]enabledRemoteNotificationTypes]// iOS7.0
8.0及之后的接口獲取的type分為以下幾種
typedef NS_OPTIONS(NSUInteger, UIUserNotificationType) {
UIUserNotificationTypeNone? ? = 0,? ? ? // the application may not present any UI upon a notification being received
UIUserNotificationTypeBadge? = 1 << 0, // the application may badge its icon upon a notification being received
UIUserNotificationTypeSound? = 1 << 1, // the application may play a sound upon a notification being received
UIUserNotificationTypeAlert? = 1 << 2, // the application may display an alert upon a notification being received
} NS_ENUM_DEPRECATED_IOS(8_0, 10_0, "Use UserNotifications Framework's UNAuthorizationOptions") __TVOS_PROHIBITED;
如果得到的UIUserNotificationType為UIUserNotificationTypeNone,則我們需要提示用戶跳轉到設置打開通知開關。
NSURL*url = [NSURLURLWithString:@"prefs:root=NOTIFICATIONS_ID"];
if([[UIApplicationsharedApplication]canOpenURL:url])
{
[[UIApplicationsharedApplication]openURL:url];
}
直接從app跳轉到相關的設置界面的另外以下Url參數(shù)如下,可進行參考:
About — prefs:root=General&path=About
Accessibility — prefs:root=General&path=ACCESSIBILITY
Airplane Mode On — prefs:root=AIRPLANE_MODE
Auto-Lock — prefs:root=General&path=AUTOLOCK
Brightness — prefs:root=Brightness
Bluetooth — prefs:root=General&path=Bluetooth
Date & Time — prefs:root=General&path=DATE_AND_TIME
FaceTime — prefs:root=FACETIME
General — prefs:root=General
Keyboard — prefs:root=General&path=Keyboard
iCloud — prefs:root=CASTLE
iCloud Storage & Backup — prefs:root=CASTLE&path=STORAGE_AND_BACKUP
International — prefs:root=General&path=INTERNATIONAL
Location Services — prefs:root=LOCATION_SERVICES
Music — prefs:root=MUSIC
Music Equalizer — prefs:root=MUSIC&path=EQ
Music Volume Limit — prefs:root=MUSIC&path=VolumeLimit
Network — prefs:root=General&path=Network
Nike + iPod — prefs:root=NIKE_PLUS_IPOD
Notes — prefs:root=NOTES
Notification — prefs:root=NOTIFICATIONS_ID
Phone — prefs:root=Phone
Photos — prefs:root=Photos
Profile — prefs:root=General&path=ManagedConfigurationList
Reset — prefs:root=General&path=Reset
Safari — prefs:root=Safari
Siri — prefs:root=General&path=Assistant
Sounds — prefs:root=Sounds
Software Update — prefs:root=General&path=SOFTWARE_UPDATE_LINK
Store — prefs:root=STORE
Twitter — prefs:root=TWITTER
Usage — prefs:root=General&path=USAGE
VPN — prefs:root=General&path=Network/VPN
Wallpaper — prefs:root=Wallpaper
Wi-Fi — prefs:root=WIFI。