iOS UIKit框架学习—UIApplication

在iOS中UIApplication类提供一个集中点控制和协调应用程序的运行。每个APP都有一个UIApplication实例对象,当程序启动的时候通过调用UIApplicationMain方法,创建单例对象UIApplication。此后可以通过sharedApplication()可以得到方法。

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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
@protocol UIApplicationDelegate;
@interface UIApplication : UIResponder
#if UIKIT_DEFINE_AS_PROPERTIES
@property(class, nonatomic, readonly) UIApplication *sharedApplication NS_EXTENSION_UNAVAILABLE_IOS("Use view controller based solutions where appropriate instead.");
#else
+ (UIApplication *)sharedApplication NS_EXTENSION_UNAVAILABLE_IOS("Use view controller based solutions where appropriate instead.");
#endif
@property(nullable, nonatomic, assign) id<UIApplicationDelegate> delegate;
// 开始、结束响应事件
- (void)beginIgnoringInteractionEvents NS_EXTENSION_UNAVAILABLE_IOS("");
- (void)endIgnoringInteractionEvents NS_EXTENSION_UNAVAILABLE_IOS("");
// 是否响应事件
#if UIKIT_DEFINE_AS_PROPERTIES
@property(nonatomic, readonly, getter=isIgnoringInteractionEvents) BOOL ignoringInteractionEvents;
#else
- (BOOL)isIgnoringInteractionEvents;
#endif
// 屏幕长亮
@property(nonatomic,getter=isIdleTimerDisabled) BOOL idleTimerDisabled; // default is NO
// 打开URL资源
- (BOOL)openURL:(NSURL*)url NS_DEPRECATED_IOS(2_0, 10_0, "Please use openURL:options:completionHandler: instead") NS_EXTENSION_UNAVAILABLE_IOS("");
// 返回一个bool值, 是否从已经安装的 apps 中跳转
- (BOOL)canOpenURL:(NSURL *)url NS_AVAILABLE_IOS(3_0);
// 异步打开URL资源
- (void)openURL:(NSURL*)url options:(NSDictionary<NSString *, id> *)options completionHandler:(void (^ __nullable)(BOOL success))completion NS_AVAILABLE_IOS(10_0) NS_EXTENSION_UNAVAILABLE_IOS("");
// 发送事件给app内适用的响应者
- (void)sendEvent:(UIEvent *)event;
// app的主视图
@property(nullable, nonatomic,readonly) UIWindow *keyWindow;
// 隐藏和可见的所有window
@property(nonatomic,readonly) NSArray<__kindof UIWindow *> *windows;
// 发送一个含选择器的动作消息到指定的目标
- (BOOL)sendAction:(SEL)action to:(nullable id)target from:(nullable id)sender forEvent:(nullable UIEvent *)event;
// 是否在状态栏展示网络请求活动
@property(nonatomic,getter=isNetworkActivityIndicatorVisible) BOOL networkActivityIndicatorVisible __TVOS_PROHIBITED; // default is NO
// 获取状态栏的风格
@property(readonly, nonatomic) UIStatusBarStyle statusBarStyle __TVOS_PROHIBITED;
// 状态栏是否隐藏
@property(readonly, nonatomic,getter=isStatusBarHidden) BOOL statusBarHidden __TVOS_PROHIBITED;
// 当前状态栏的方向
@property(readonly, nonatomic) UIInterfaceOrientation statusBarOrientation __TVOS_PROHIBITED;
// 实现代理设置屏幕支持的方向
- (UIInterfaceOrientationMask)supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window NS_AVAILABLE_IOS(6_0) __TVOS_PROHIBITED;
// 获取旋转屏幕的时间
@property(nonatomic,readonly) NSTimeInterval statusBarOrientationAnimationDuration __TVOS_PROHIBITED;
// 获取状态栏的frame
@property(nonatomic,readonly) CGRect statusBarFrame __TVOS_PROHIBITED;
// 应用角标未读消息数字,设置0的时候隐藏,在iOS 8 必须注册后才能使用: -[UIApplication registerUserNotificationSettings:]
@property(nonatomic) NSInteger applicationIconBadgeNumber;
// 是否支持摇动手势
@property(nonatomic) BOOL applicationSupportsShakeToEdit NS_AVAILABLE_IOS(3_0) __TVOS_PROHIBITED;
// 应用的运行状态
@property(nonatomic,readonly) UIApplicationState applicationState NS_AVAILABLE_IOS(4_0);
// 后台运行剩余时间
@property(nonatomic,readonly) NSTimeInterval backgroundTimeRemaining NS_AVAILABLE_IOS(4_0);
// 后台任务管理
- (UIBackgroundTaskIdentifier)beginBackgroundTaskWithExpirationHandler:(void(^ __nullable)(void))handler NS_AVAILABLE_IOS(4_0) NS_REQUIRES_SUPER;
- (UIBackgroundTaskIdentifier)beginBackgroundTaskWithName:(nullable NSString *)taskName expirationHandler:(void(^ __nullable)(void))handler NS_AVAILABLE_IOS(7_0) NS_REQUIRES_SUPER;
- (void)endBackgroundTask:(UIBackgroundTaskIdentifier)identifier NS_AVAILABLE_IOS(4_0) NS_REQUIRES_SUPER;
// 设置后台拉去数据的时间
- (void)setMinimumBackgroundFetchInterval:(NSTimeInterval)minimumBackgroundFetchInterval NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;
// 获取后台刷新状态
@property (nonatomic, readonly) UIBackgroundRefreshStatus backgroundRefreshStatus NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;
// 是否启用数据保护 YES:未启用
@property(nonatomic,readonly,getter=isProtectedDataAvailable) BOOL protectedDataAvailable NS_AVAILABLE_IOS(4_0);
// 返回界面的布局方向
@property(nonatomic,readonly) UIUserInterfaceLayoutDirection userInterfaceLayoutDirection NS_AVAILABLE_IOS(5_0);
// 返回字体大小
@property(nonatomic,readonly) UIContentSizeCategory preferredContentSizeCategory NS_AVAILABLE_IOS(7_0);
@end
// 远程通知
@interface UIApplication (UIRemoteNotifications)
// 通过苹果推送通知注册接收远程通知服务
- (void)registerForRemoteNotifications NS_AVAILABLE_IOS(8_0);
// 注销远程通知服务
- (void)unregisterForRemoteNotifications NS_AVAILABLE_IOS(3_0);
// 应用是否注册了远程通知服务
#if UIKIT_DEFINE_AS_PROPERTIES
@property(nonatomic, readonly, getter=isRegisteredForRemoteNotifications) BOOL registeredForRemoteNotifications NS_AVAILABLE_IOS(8_0);
#else
- (BOOL)isRegisteredForRemoteNotifications NS_AVAILABLE_IOS(8_0);
#endif
// 通过注册苹果的远程推送通知,接收指定类型的服务
- (void)registerForRemoteNotificationTypes:(UIRemoteNotificationType)types NS_DEPRECATED_IOS(3_0, 8_0, "Use -[UIApplication registerForRemoteNotifications] and UserNotifications Framework's -[UNUserNotificationCenter requestAuthorizationWithOptions:completionHandler:]") __TVOS_PROHIBITED;
// 返回应用通知的接收类型
- (UIRemoteNotificationType)enabledRemoteNotificationTypes NS_DEPRECATED_IOS(3_0, 8_0, "Use -[UIApplication isRegisteredForRemoteNotifications] and UserNotifications Framework's -[UNUserNotificationCenter getNotificationSettingsWithCompletionHandler:] to retrieve user-enabled remote notification and user notification settings") __TVOS_PROHIBITED;
@end
// 本地通知
@interface UIApplication (UILocalNotifications)
// 立即呈现本地通知
- (void)presentLocalNotificationNow:(UILocalNotification *)notification NS_DEPRECATED_IOS(4_0, 10_0, "Use UserNotifications Framework's -[UNUserNotificationCenter addNotificationRequest:withCompletionHandler:]") __TVOS_PROHIBITED;
// 本地安排通知
- (void)scheduleLocalNotification:(UILocalNotification *)notification NS_DEPRECATED_IOS(4_0, 10_0, "Use UserNotifications Framework's -[UNUserNotificationCenter addNotificationRequest:withCompletionHandler:]") __TVOS_PROHIBITED; // copies notification
// 取消指定的本地通吃
- (void)cancelLocalNotification:(UILocalNotification *)notification NS_DEPRECATED_IOS(4_0, 10_0, "Use UserNotifications Framework's -[UNUserNotificationCenter removePendingNotificationRequestsWithIdentifiers:]") __TVOS_PROHIBITED;
// 取消所有的本地通知
- (void)cancelAllLocalNotifications NS_DEPRECATED_IOS(4_0, 10_0, "Use UserNotifications Framework's -[UNUserNotificationCenter removeAllPendingNotificationRequests]") __TVOS_PROHIBITED;
// 返回本地日程安排通知数组
@property(nullable,nonatomic,copy) NSArray<UILocalNotification *> *scheduledLocalNotifications NS_DEPRECATED_IOS(4_0, 10_0, "Use UserNotifications Framework's -[UNUserNotificationCenter getPendingNotificationRequestsWithCompletionHandler:]") __TVOS_PROHIBITED;
@end
// 设置通知
@class UIUserNotificationSettings;
@interface UIApplication (UIUserNotificationSettings)
// 注册通知
- (void)registerUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings NS_AVAILABLE_IOS(8_0) __TVOS_PROHIBITED;
// 返回当前用户启用的通知
#if UIKIT_DEFINE_AS_PROPERTIES
@property(nonatomic, readonly, nullable) UIUserNotificationSettings *currentUserNotificationSettings NS_AVAILABLE_IOS(8_0) __TVOS_PROHIBITED;
#else
- (nullable UIUserNotificationSettings *)currentUserNotificationSettings NS_AVAILABLE_IOS(8_0) __TVOS_PROHIBITED;
#endif
@end
// 远程控制事件
@interface UIApplication (UIRemoteControlEvents)
// 开始接受远程遥控事件
- (void)beginReceivingRemoteControlEvents NS_AVAILABLE_IOS(4_0);
// 停止接受远程遥控事件
- (void)endReceivingRemoteControlEvents NS_AVAILABLE_IOS(4_0);
@end
@interface UIApplication (UINewsstand)
// 设置一个报摊的icon
- (void)setNewsstandIconImage:(nullable UIImage *)image NS_DEPRECATED_IOS(5_0, 9_0, "Newsstand apps now behave like normal apps on SpringBoard") __TVOS_PROHIBITED;
@end
@class UIApplicationShortcutItem;
// 管理3D Touch的快速操作
@interface UIApplication (UIShortcutItems)
// 主屏幕用户使用3D Touch功能的菜单数组
@property (nullable, nonatomic, copy) NSArray<UIApplicationShortcutItem *> *shortcutItems NS_AVAILABLE_IOS(9_0) __TVOS_PROHIBITED;
@end
// 管理恢复状态行为
@protocol UIStateRestoring;
@interface UIApplication (UIStateRestoration)
// 正在恢复状态
- (void)extendStateRestoration NS_AVAILABLE_IOS(6_0);
// 恢复完成状态
- (void)completeStateRestoration NS_AVAILABLE_IOS(6_0);
// 防止应用在一个启动的声明周期使用最近的屏幕快照
- (void)ignoreSnapshotOnNextApplicationLaunch NS_AVAILABLE_IOS(7_0);
// 注册一个恢复状态对象的id
+ (void)registerObjectForStateRestoration:(id<UIStateRestoring>)object restorationIdentifier:(NSString *)restorationIdentifier NS_AVAILABLE_IOS(7_0);
@end
#if UIKIT_STRING_ENUMS
typedef NSString * UIApplicationLaunchOptionsKey NS_EXTENSIBLE_STRING_ENUM;
#else
typedef NSString * UIApplicationLaunchOptionsKey;
#endif
@protocol UIApplicationDelegate<NSObject>
@optional
// 应用生命周期
// 应用启动完成执行
- (void)applicationDidFinishLaunching:(UIApplication *)application;
#if UIKIT_STRING_ENUMS
// 应用启动进程已经开始,但部分状态没有完全恢复
- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(nullable NSDictionary<UIApplicationLaunchOptionsKey, id> *)launchOptions NS_AVAILABLE_IOS(6_0);
// 告诉代理启动基本完成程序准备开始运行(加载到窗口,可以看到)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(nullable NSDictionary<UIApplicationLaunchOptionsKey, id> *)launchOptions NS_AVAILABLE_IOS(3_0);
#else
- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(nullable NSDictionary *)launchOptions NS_AVAILABLE_IOS(6_0);
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(nullable NSDictionary *)launchOptions NS_AVAILABLE_IOS(3_0);
#endif
// 当应用程序回到激活状态执行 (回到窗口,可以看到)
- (void)applicationDidBecomeActive:(UIApplication *)application;
// 当应用程序将要进入非活动状态执行,在此期间,应用程序不接收消息或事件,比如来电话了
- (void)applicationWillResignActive:(UIApplication *)application;
// 请求委托打开由url标示的资源
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url NS_DEPRECATED_IOS(2_0, 9_0, "Please use application:openURL:options:") __TVOS_PROHIBITED;
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(nullable NSString *)sourceApplication annotation:(id)annotation NS_DEPRECATED_IOS(4_2, 9_0, "Please use application:openURL:options:") __TVOS_PROHIBITED;
#if UIKIT_STRING_ENUMS
typedef NSString * UIApplicationOpenURLOptionsKey NS_EXTENSIBLE_STRING_ENUM;
#else
typedef NSString * UIApplicationOpenURLOptionsKey;
#endif
// 请求委托打开由url标示的资源
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options NS_AVAILABLE_IOS(9_0);
// 接收来自系统内存警告
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application;
// 当程序将要退出是被调用,通常是用来保存数据和一些退出前的清理工作。这个需要要设置
- (void)applicationWillTerminate:(UIApplication *)application;
// 重要时间的变化
- (void)applicationSignificantTimeChange:(UIApplication *)application; // midnight, carrier time update, daylight savings time change
// 当状态栏的方向即将要发生改变时执行
- (void)application:(UIApplication *)application willChangeStatusBarOrientation:(UIInterfaceOrientation)newStatusBarOrientation duration:(NSTimeInterval)duration __TVOS_PROHIBITED;
// 当状态栏的方向发生改变时执行
- (void)application:(UIApplication *)application didChangeStatusBarOrientation:(UIInterfaceOrientation)oldStatusBarOrientation __TVOS_PROHIBITED;
// 当状态栏的frame即将要发生改变时执行
- (void)application:(UIApplication *)application willChangeStatusBarFrame:(CGRect)newStatusBarFrame __TVOS_PROHIBITED; // in screen coordinates
// 当状态栏的frame发生改变时执行
- (void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)oldStatusBarFrame __TVOS_PROHIBITED;
// 处理本地和远程通知
// 注册本地或远程通知类型
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings NS_AVAILABLE_IOS(8_0) __TVOS_PROHIBITED;
// 远程推送通知注册成功回调
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken NS_AVAILABLE_IOS(3_0);
// 无法成功注册推送通知服务回调
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error NS_AVAILABLE_IOS(3_0);
// 收到远程推送通知执行
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo NS_DEPRECATED_IOS(3_0, 10_0, "Use UserNotifications Framework's -[UNUserNotificationCenterDelegate willPresentNotification:withCompletionHandler:] or -[UNUserNotificationCenterDelegate didReceiveNotificationResponse:withCompletionHandler:] for user visible notifications and -[UIApplicationDelegate application:didReceiveRemoteNotification:fetchCompletionHandler:] for silent remote notifications");
// 收到本地推送通知执行
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification NS_DEPRECATED_IOS(4_0, 10_0, "Use UserNotifications Framework's -[UNUserNotificationCenterDelegate willPresentNotification:withCompletionHandler:] or -[UNUserNotificationCenterDelegate didReceiveNotificationResponse:withCompletionHandler:]") __TVOS_PROHIBITED;
// 当应用被激活时,处理用户从本地推送通知中选择操作的事件
- (void)application:(UIApplication *)application handleActionWithIdentifier:(nullable NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void(^)())completionHandler NS_DEPRECATED_IOS(8_0, 10_0, "Use UserNotifications Framework's -[UNUserNotificationCenterDelegate didReceiveNotificationResponse:withCompletionHandler:]") __TVOS_PROHIBITED;
// 当应用被激活时,处理用户从远程推送通知中选择操作的事件
- (void)application:(UIApplication *)application handleActionWithIdentifier:(nullable NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo withResponseInfo:(NSDictionary *)responseInfo completionHandler:(void(^)())completionHandler NS_DEPRECATED_IOS(9_0, 10_0, "Use UserNotifications Framework's -[UNUserNotificationCenterDelegate didReceiveNotificationResponse:withCompletionHandler:]") __TVOS_PROHIBITED;
- (void)application:(UIApplication *)application handleActionWithIdentifier:(nullable NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler NS_DEPRECATED_IOS(8_0, 10_0, "Use UserNotifications Framework's -[UNUserNotificationCenterDelegate didReceiveNotificationResponse:withCompletionHandler:]") __TVOS_PROHIBITED;
- (void)application:(UIApplication *)application handleActionWithIdentifier:(nullable NSString *)identifier forLocalNotification:(UILocalNotification *)notification withResponseInfo:(NSDictionary *)responseInfo completionHandler:(void(^)())completionHandler NS_DEPRECATED_IOS(9_0, 10_0, "Use UserNotifications Framework's -[UNUserNotificationCenterDelegate didReceiveNotificationResponse:withCompletionHandler:]") __TVOS_PROHIBITED;
// 一个远程通知到达,表明有数据要获取
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler NS_AVAILABLE_IOS(7_0);
// 如果有有数据下载,它可以开始获取操作
- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;
// 主屏幕3D Touch快捷选项操作启动应用执行
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void(^)(BOOL succeeded))completionHandler NS_AVAILABLE_IOS(9_0) __TVOS_PROHIBITED;
// 与URL有关的事件正等待处理
- (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)())completionHandler NS_AVAILABLE_IOS(7_0);
// 相应Watch的配对请求
- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(nullable NSDictionary *)userInfo reply:(void(^)(NSDictionary * __nullable replyInfo))reply NS_AVAILABLE_IOS(8_2);
// 应用将要获取用户健康数据时调用
- (void)applicationShouldRequestHealthAuthorization:(UIApplication *)application NS_AVAILABLE_IOS(9_0);
// 当程序被推送到后台的时候调用
- (void)applicationDidEnterBackground:(UIApplication *)application NS_AVAILABLE_IOS(4_0);
// 当程序将要被推送到前台的时候调用
- (void)applicationWillEnterForeground:(UIApplication *)application NS_AVAILABLE_IOS(4_0);
// 保护文件不可用
- (void)applicationProtectedDataWillBecomeUnavailable:(UIApplication *)application NS_AVAILABLE_IOS(4_0);
// 保护文件可用
- (void)applicationProtectedDataDidBecomeAvailable:(UIApplication *)application NS_AVAILABLE_IOS(4_0);
// 呈现的故事版
@property (nullable, nonatomic, strong) UIWindow *window NS_AVAILABLE_IOS(5_0);
// 应用视图支持的方向
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window NS_AVAILABLE_IOS(6_0) __TVOS_PROHIBITED;
#if UIKIT_STRING_ENUMS
typedef NSString * UIApplicationExtensionPointIdentifier NS_EXTENSIBLE_STRING_ENUM;
#else
typedef NSString * UIApplicationExtensionPointIdentifier;
#endif
// 将要扩展的指定标识符的应用
- (BOOL)application:(UIApplication *)application shouldAllowExtensionPointIdentifier:(UIApplicationExtensionPointIdentifier)extensionPointIdentifier NS_AVAILABLE_IOS(8_0);
#pragma mark -- State Restoration protocol adopted by UIApplication delegate --
// 提供指定视图控制器
- (nullable UIViewController *) application:(UIApplication *)application viewControllerWithRestorationIdentifierPath:(NSArray *)identifierComponents coder:(NSCoder *)coder NS_AVAILABLE_IOS(6_0);
// 是否保存应用的状态信息 ↓
- (BOOL) application:(UIApplication *)application shouldSaveApplicationState:(NSCoder *)coder NS_AVAILABLE_IOS(6_0);
// 是否恢复应用保存的状态信息 ↑
- (BOOL) application:(UIApplication *)application shouldRestoreApplicationState:(NSCoder *)coder NS_AVAILABLE_IOS(6_0);
// 处理保存高级状态的信息
- (void) application:(UIApplication *)application willEncodeRestorableStateWithCoder:(NSCoder *)coder NS_AVAILABLE_IOS(6_0);
// 恢复一部分保存的高级状态的信息
- (void) application:(UIApplication *)application didDecodeRestorableStateWithCoder:(NSCoder *)coder NS_AVAILABLE_IOS(6_0);
#pragma mark -- User Activity Continuation protocol adopted by UIApplication delegate --
// 当活动比预期时间长的时候,是否继续通知
- (BOOL)application:(UIApplication *)application willContinueUserActivityWithType:(NSString *)userActivityType NS_AVAILABLE_IOS(8_0);
// 告诉继续活动期间数据是否可用
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void(^)(NSArray * __nullable restorableObjects))restorationHandler NS_AVAILABLE_IOS(8_0);
// 应用注册远程推送通知失败时激发该方法
- (void)application:(UIApplication *)application didFailToContinueUserActivityWithType:(NSString *)userActivityType error:(NSError *)error NS_AVAILABLE_IOS(8_0);
// 更新活动
- (void)application:(UIApplication *)application didUpdateUserActivity:(NSUserActivity *)userActivity NS_AVAILABLE_IOS(8_0);
#pragma mark -- CloudKit Sharing Invitation Handling --
// 同意接受云共享请求
- (void) application:(UIApplication *)application userDidAcceptCloudKitShareWithMetadata:(CKShareMetadata *)cloudKitShareMetadata NS_AVAILABLE_IOS(10_0);
@end
@interface UIApplication(UIApplicationDeprecated)
// 获取状态栏的方向
@property(readwrite, nonatomic) UIInterfaceOrientation statusBarOrientation NS_DEPRECATED_IOS(2_0, 9_0, "Explicit setting of the status bar orientation is more limited in iOS 6.0 and later") __TVOS_PROHIBITED;
// 设置状态栏的方向
- (void)setStatusBarOrientation:(UIInterfaceOrientation)interfaceOrientation animated:(BOOL)animated NS_DEPRECATED_IOS(2_0, 9_0, "Explicit setting of the status bar orientation is more limited in iOS 6.0 and later") __TVOS_PROHIBITED;
// 当前状态栏的样式
@property(readwrite, nonatomic) UIStatusBarStyle statusBarStyle NS_DEPRECATED_IOS(2_0, 9_0, "Use -[UIViewController preferredStatusBarStyle]") __TVOS_PROHIBITED;
// 设置状态栏的样式
- (void)setStatusBarStyle:(UIStatusBarStyle)statusBarStyle animated:(BOOL)animated NS_DEPRECATED_IOS(2_0, 9_0, "Use -[UIViewController preferredStatusBarStyle]") __TVOS_PROHIBITED;
// 当前状态栏是否隐藏
@property(readwrite, nonatomic,getter=isStatusBarHidden) BOOL statusBarHidden NS_DEPRECATED_IOS(2_0, 9_0, "Use -[UIViewController prefersStatusBarHidden]") __TVOS_PROHIBITED;
// 隐藏状态栏
- (void)setStatusBarHidden:(BOOL)hidden withAnimation:(UIStatusBarAnimation)animation NS_DEPRECATED_IOS(3_2, 9_0, "Use -[UIViewController prefersStatusBarHidden]") __TVOS_PROHIBITED;
// 设置后台停留时间
- (BOOL)setKeepAliveTimeout:(NSTimeInterval)timeout handler:(void(^ __nullable)(void))keepAliveHandler NS_DEPRECATED_IOS(4_0, 9_0, "Please use UIRemoteNotificationTypeVoIP remote notifications for VoIP applications") __TVOS_PROHIBITED;
// 清除后台停留时间
- (void)clearKeepAliveTimeout NS_DEPRECATED_IOS(4_0, 9_0, "Please use UIRemoteNotificationTypeVoIP remote notifications for VoIP applications") __TVOS_PROHIBITED;
@end
// 创建应用程序的主要入口
UIKIT_EXTERN int UIApplicationMain(int argc, char *argv[], NSString * __nullable principalClassName, NSString * __nullable delegateClassName);
// 省略一部分全局变量
@end
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
// 状态栏风格
typedef NS_ENUM(NSInteger, UIStatusBarStyle) {
UIStatusBarStyleDefault = 0, // 黑色,用于亮的背景
UIStatusBarStyleLightContent NS_ENUM_AVAILABLE_IOS(7_0) = 1, // 白色,用于深色背景
UIStatusBarStyleBlackTranslucent NS_ENUM_DEPRECATED_IOS(2_0, 7_0, "Use UIStatusBarStyleLightContent") = 1,
UIStatusBarStyleBlackOpaque NS_ENUM_DEPRECATED_IOS(2_0, 7_0, "Use UIStatusBarStyleLightContent") = 2,
} __TVOS_PROHIBITED;
// 状态栏动画效果
typedef NS_ENUM(NSInteger, UIStatusBarAnimation) {
UIStatusBarAnimationNone, // 无
UIStatusBarAnimationFade NS_ENUM_AVAILABLE_IOS(3_2), // 褪去
UIStatusBarAnimationSlide NS_ENUM_AVAILABLE_IOS(3_2), // 滑出
} __TVOS_PROHIBITED;
// 支持屏幕旋转的方向
// UIDeviceOrientation:是机器硬件的当前旋转方向,这个你只能取值,不能设置
// UIInterfaceOrientation:是你程序界面的当前旋转方向,这个可以设置
typedef NS_ENUM(NSInteger, UIInterfaceOrientation) {
UIInterfaceOrientationUnknown = UIDeviceOrientationUnknown, // 不支持屏幕旋转
UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait, // 支持旋转
UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown, // 旋转180°
UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight, // 顺时针 向右旋转90°
UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft // 逆时针旋转 向左旋转90°
} __TVOS_PROHIBITED;
// 设置屏幕支持旋转的方向
typedef NS_OPTIONS(NSUInteger, UIInterfaceOrientationMask) {
UIInterfaceOrientationMaskPortrait = (1 << UIInterfaceOrientationPortrait),
UIInterfaceOrientationMaskLandscapeLeft = (1 << UIInterfaceOrientationLandscapeLeft), // 向左旋转90°
UIInterfaceOrientationMaskLandscapeRight = (1 << UIInterfaceOrientationLandscapeRight), // 向右旋转90°
UIInterfaceOrientationMaskPortraitUpsideDown = (1 << UIInterfaceOrientationPortraitUpsideDown), // 旋转180°
UIInterfaceOrientationMaskLandscape = (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight), // 向左右旋转即横屏
UIInterfaceOrientationMaskAll = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown), // 支持任意方向旋转
UIInterfaceOrientationMaskAllButUpsideDown = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight), // 除旋转180°所有方向
} __TVOS_PROHIBITED;
// 判断旋转是否有效
#define UIDeviceOrientationIsValidInterfaceOrientation(orientation) ((UIDeviceOrientation)(orientation) == UIDeviceOrientationPortrait || (UIDeviceOrientation)(orientation) == UIDeviceOrientationPortraitUpsideDown || (UIDeviceOrientation)(orientation) == UIDeviceOrientationLandscapeLeft || (UIDeviceOrientation)(orientation) == UIDeviceOrientationLandscapeRight)
// 屏幕是否横屏
static inline BOOL UIInterfaceOrientationIsPortrait(UIInterfaceOrientation orientation) __TVOS_PROHIBITED {
return ((orientation) == UIInterfaceOrientationPortrait || (orientation) == UIInterfaceOrientationPortraitUpsideDown);
}
// 屏幕是否竖屏
static inline BOOL UIInterfaceOrientationIsLandscape(UIInterfaceOrientation orientation) __TVOS_PROHIBITED {
return ((orientation) == UIInterfaceOrientationLandscapeLeft || (orientation) == UIInterfaceOrientationLandscapeRight);
}
// 注册远程通知 角标、声音、提示
typedef NS_OPTIONS(NSUInteger, UIRemoteNotificationType) {
UIRemoteNotificationTypeNone = 0,
UIRemoteNotificationTypeBadge = 1 << 0,
UIRemoteNotificationTypeSound = 1 << 1,
UIRemoteNotificationTypeAlert = 1 << 2,
UIRemoteNotificationTypeNewsstandContentAvailability = 1 << 3,
} NS_ENUM_DEPRECATED_IOS(3_0, 8_0, "Use UserNotifications Framework's UNAuthorizationOptions for user notifications and registerForRemoteNotifications for receiving remote notifications instead.") __TVOS_PROHIBITED;
// 后台处理拉取数据结果类型
typedef NS_ENUM(NSUInteger, UIBackgroundFetchResult) {
UIBackgroundFetchResultNewData, // 成功拉去数据
UIBackgroundFetchResultNoData, // 没有数据
UIBackgroundFetchResultFailed // 拉出数据失败或超时
} NS_ENUM_AVAILABLE_IOS(7_0);
// 后台刷新状态
typedef NS_ENUM(NSInteger, UIBackgroundRefreshStatus) {
UIBackgroundRefreshStatusRestricted, // 受限制
UIBackgroundRefreshStatusDenied, // 被拒绝
UIBackgroundRefreshStatusAvailable // 可用
} NS_ENUM_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;
// app 运行状态
typedef NS_ENUM(NSInteger, UIApplicationState) {
UIApplicationStateActive, // 在前台运行
UIApplicationStateInactive, // 待激活状态:锁屏、下拉看通知、任务管理
UIApplicationStateBackground // 在后台运行:按下home键
} NS_ENUM_AVAILABLE_IOS(4_0);
// 任务标示
typedef NSUInteger UIBackgroundTaskIdentifier;
// 设置无效的任务
UIKIT_EXTERN const UIBackgroundTaskIdentifier UIBackgroundTaskInvalid NS_AVAILABLE_IOS(4_0);
// 后台保持的最小时间
UIKIT_EXTERN const NSTimeInterval UIMinimumKeepAliveTimeout NS_AVAILABLE_IOS(4_0);
// 请求的最小间隔(刷新最频繁)
UIKIT_EXTERN const NSTimeInterval UIApplicationBackgroundFetchIntervalMinimum NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;
// 请求的最大间隔,阻止请求(不刷新)
UIKIT_EXTERN const NSTimeInterval UIApplicationBackgroundFetchIntervalNever NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;