菜鸟教程——常用功能之提醒用户打开通知

2017-04-21  本文已影响0人  iOS谢先森

在app初次运行时会提醒用户是否开启通知,从而实现消息推送功能。如果用户未打开消息通知则我们需要定时提醒用户开启。

我们可以通过下面这个方法查看通知设置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参数如下,可进行参考:

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。

上一篇下一篇

猜你喜欢

热点阅读