UIApplication+YOHO.m
1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
// UIApplication+YOHO.m
// YH_Mall
//
// Created by Haizi on 16/5/30.
// Copyright © 2016年 YOHO. All rights reserved.
//
#import "UIApplication+YOHO.h"
@implementation UIApplication (YOHO)
- (void)registerRemoteNotification
{
if([[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] != NSOrderedAscending){
UIUserNotificationSettings *notiSettings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIRemoteNotificationTypeSound) categories:nil];
[self registerUserNotificationSettings:notiSettings];
}else{
[self registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound];
}
}
- (void)clearNotificationMark
{
[self setApplicationIconBadgeNumber:1];
[self setApplicationIconBadgeNumber:0];
NSArray* scheduledNotifications = [NSArray arrayWithArray:self.scheduledLocalNotifications];
self.scheduledLocalNotifications = scheduledNotifications;
[self cancelAllLocalNotifications];
}
- (BOOL)enabledRemoteNotification
{
BOOL enable = YES;
if ([[UIApplication sharedApplication] respondsToSelector:@selector(currentUserNotificationSettings)]) {
enable = ([[UIApplication sharedApplication] currentUserNotificationSettings].types != UIUserNotificationTypeNone);
}else{
enable =([[UIApplication sharedApplication] enabledRemoteNotificationTypes] != UIRemoteNotificationTypeNone);
}
return enable;
}
- (void)openAppSystemSettingPage
{
NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if([[UIApplication sharedApplication] canOpenURL:url]) {
NSURL*url =[NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:url];
}
}
@end