forked from appwoodpecker/woodpecker-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppDelegate.m
143 lines (102 loc) · 6.54 KB
/
AppDelegate.m
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//
// AppDelegate.m
// ADHClient
//
// Created by 张小刚 on 2017/10/26.
// Copyright © 2017年 lifebetter. All rights reserved.
//
#import "AppDelegate.h"
#import "TestViewController.h"
@import UserNotifications;
@import UserNotificationsUI;
@interface AppDelegate ()<UNUserNotificationCenterDelegate>
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
/*
//host name
[[NSUserDefaults standardUserDefaults] setObject:@"李雷" forKey:kADHHostName];
//host address
[[NSUserDefaults standardUserDefaults] setObject:@"192.168.1.101:9999" forKey:kADHHostAddress];
//disable auto connect
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:NO] forKey:kADHAutoConnectEnabled];
//not show setting page
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:NO] forKey:kADHShowOnConnectionFailed];
//ui gesture disable
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:NO] forKey:kADHUIGestureEnabled];
*/
UIWindow * window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
window.backgroundColor = [UIColor whiteColor];
TestViewController * testVC = [[TestViewController alloc] init];
UINavigationController * nvc = [[UINavigationController alloc] initWithRootViewController:testVC];
window.rootViewController = nvc;
[window makeKeyAndVisible];
self.window = window;
[self setupNotification];
[self otherSetting];
return YES;
}
- (void)setupNotification {
UNUserNotificationCenter * notiCenter = [UNUserNotificationCenter currentNotificationCenter];
notiCenter.delegate = self;
UNNotificationAction *openAction = [UNNotificationAction actionWithIdentifier:UNNotificationDefaultActionIdentifier title:@"Okay" options:0];
UNNotificationAction *customAction = [UNNotificationAction actionWithIdentifier:@"customaction" title:@"Do Something" options:0];
UNNotificationCategory *category = [UNNotificationCategory categoryWithIdentifier:@"actionCategory" actions:@[openAction,customAction] intentIdentifiers:@[] options:0];
NSSet *set = [NSSet setWithObjects:category, nil];
[notiCenter setNotificationCategories:set];
}
- (void)otherSetting {
// [FIRApp configure];
// [[FIRRemoteConfig remoteConfig] setDefaultsFromPlistFileName:@"RemoteConfigDefaults"];
}
#pragma mark ----------------- notification ----------------
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
// [[ADHNotificationService sharedService] didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSLog(@"did fail to register remote notifiation: %@",error);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
// [[ADHNotificationService sharedService] didReceiveRemoteNotification:userInfo];
NSLog(@"%@",userInfo);
}
/** The method will be called on the delegate only if the application is in the foreground. If the method is not implemented or the handler is not called in a timely manner then the notification will not be presented. The application can choose to have the notification presented as a sound, badge, alert and/or in the notification list. This decision should be based on whether the information in the notification is otherwise visible to the user.
用户在前台时收到此消息,并决定如何处理
可以用系统通知框或者自定义操作(不使用系统UI,自己做其他处理)
*/
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
{
NSLog(@"will present notification");
completionHandler(UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert|UNNotificationPresentationOptionBadge);
}
/** The method will be called on the delegate when the user responded to the notification by opening the application, dismissing the notification or choosing a UNNotificationAction. The delegate must be set before the application returns from application:didFinishLaunchingWithOptions:.
应用在前台,用户操作通知(open(default),dismiss,custom action)
应用在后台运行,用户操作通知
*/
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler
{
NSLog(@"did receive notification: %@",response.actionIdentifier);
completionHandler();
[[NSUserDefaults standardUserDefaults] setValue:[NSDate date] forKey:@"didReceiveNotificationResponse"];
}
- (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@end