UIApplication详解

每个app有且只有一个UIApplication对象,当程序启动的时候通过调用UIApplicationMain方法得到的。可以通过sharedApplication方法得到。

UIApplication对象的主要任务是处理用户事件的处理路径,例如分发一个UIEvent到另外一个对象去处理。UIApplication对象持有众多的UIWindow对象,因此可以组织app的展示。UIApplication对象还能处理一些资源,例如通过openURL:打开邮箱客户端或者设置界面等。

获得UIApplication对象

 

1. [UIApplication sharedApplication]
获得UIApplicationDelegate对象
1. [[UIApplication sharedApplication] delegate]
获得UIWindow对象
1. [[UIApplication sharedApplication] windows];   //UIWindow数组
2. [[UIApplication sharedApplication] keyWindow]; //UIWindow数组中最后调用makeKeyAndVisible方法的UIWindow对象
控制和处理UIEvent

 

 

1. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
2. {//分发一个event到另外一个对象去处理
3. [[UIApplication sharedApplication] sendAction:@selector(action: forEvent:) to:[CustomHandler sharedCustomHandler] from:self forEvent:event];
4. }
1. [[UIApplication sharedApplication] beginIgnoringInteractionEvents]; //开始忽略Event
2. //...中间调用动画等操作
3. [[UIApplication sharedApplication] endIgnoringInteractionEvents];   //结束忽略Event
1. [UIApplication sharedApplication].applicationSupportsShakeToEdit = YES;  //晃动是否有撤销或者重做动作
打开URL资源

 

 

1. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];//打开设置界面
配置通知设置

 

 

1. UIUserNotificationType  types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
2. UIUserNotificationSettings  *mySettings  = [UIUserNotificationSettings settingsForTypes:types categories:nil];
3. [[UIApplication sharedApplication] registerUserNotificationSettings:mySettings]; //注册远程推送通知
1. [[UIApplication sharedApplication] registerForRemoteNotifications];//注册
2. [[UIApplication sharedApplication] unregisterForRemoteNotifications];//注销
01. NSDate *date = [NSDate dateWithTimeIntervalSinceNow:10];
02. UILocalNotification *localNotif = [[UILocalNotification alloc] init];
03. localNotif.fireDate = date;  //时间
04. localNotif.timeZone = [NSTimeZone localTimeZone]; //时区
05. localNotif.repeatInterval = NSCalendarUnitMinute; //间隔
06. localNotif.soundName = UILocalNotificationDefaultSoundName; //声音
07. localNotif.alertBody = @"Local Test";   //通知内容
08. localNotif.applicationIconBadgeNumber = 1;  //数字标示
09. localNotif.userInfo = @{@"key":@"test"};    //info
10. [[UIApplication sharedApplication] scheduleLocalNotification:localNotif]; //注册通知
1. [[UIApplication sharedApplication] presentLocalNotificationNow:localNotif]; //立即通知
2. [[UIApplication sharedApplication] cancelAllLocalNotifications]; //取消所有通知
3. [[UIApplication sharedApplication] cancelLocalNotification:localNotif]; //取消特定的通知
4.  
5. NSArray *arr = [[UIApplication sharedApplication] scheduledLocalNotifications];  //所有的通知
后台运行相关

 

 

01. [[UIApplication sharedApplication] applicationState]; //app状态  
02. [[UIApplication sharedApplication] setMinimumBackgroundFetchInterval:3600]; //设置后台运行时间
03. NSTimeInterval remainTime = [[UIApplication sharedApplication] backgroundTimeRemaining]; //app后台运行的时间
04. NSLog(@"remainTIme = %f",remainTime);
05. int state = [[UIApplication sharedApplication] backgroundRefreshStatus]; //后台刷新的状态
06. NSLog(@"state = %d",state);
07. [[UIApplication sharedApplication] beginBackgroundTaskWithName:@"taskOne" expirationHandler:^{
08. }];
09. [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ 
10. }];
11. [[UIApplication sharedApplication] endBackgroundTask:1];
远程的控制相关

 

 

1. [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
2. [[UIApplication sharedApplication] endReceivingRemoteControlEvents];
系统的Idle Timer

 

 

1. [UIApplication sharedApplication].idleTimerDisabled = YES; //不让手机休眠
APP样式

 

 

01. //隐藏状态条
02. [[UIApplication sharedApplication] setStatusBarHidden:YES];
03. [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
04. //设置状态条的样式
05. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
06. [[UIApplication sharedApplication] statusBarStyle];
07. //状态条的Frame
08. [[UIApplication sharedApplication] statusBarFrame];
09. //网络是否可见
10. [[UIApplication sharedApplication] isNetworkActivityIndicatorVisible];
11. //badge数字
12. [UIApplication sharedApplication].applicationIconBadgeNumber = 2;
13. //屏幕的方向
14. [[UIApplication sharedApplication] userInterfaceLayoutDirection];
设置状态条的方向

 

 

1. [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:YES];
数据类型

 

 

1. UIBackgroundTaskIdentifier : Int
1. typedef enum : NSUInteger {
2. UIRemoteNotificationTypeNone    = 0,
3. UIRemoteNotificationTypeBadge   = 1 << 0,
4. UIRemoteNotificationTypeSound   = 1 << 1,
5. UIRemoteNotificationTypeAlert   = 1 << 2,
6. UIRemoteNotificationTypeNewsstandContentAvailability = 1 << 3
7. } UIRemoteNotificationType;
1. typedef enum : NSInteger {
2. UIStatusBarStyleDefault,
3. UIStatusBarStyleLightContent,
4.  
5. UIStatusBarStyleBlackTranslucent,
6. UIStatusBarStyleBlackOpaque
7. } UIStatusBarStyle;
1. typedef enum : NSInteger {
2. UIStatusBarAnimationNone,
3. UIStatusBarAnimationFade,
4. UIStatusBarAnimationSlide,
5. } UIStatusBarAnimation;
1. typedef enum : NSInteger  {
2. UIApplicationStateActive ,
3. UIApplicationStateInactive ,
4. UIApplicationStateBackground 
5. } UIApplicationState;
1. const UIBackgroundTaskIdentifier  UIBackgroundTaskInvalid ;
2. const NSTimeInterval  UIMinimumKeepAliveTimeout;
1. typedef enum : NSUInteger  {
2. UIBackgroundFetchResultNewData ,
3. UIBackgroundFetchResultNoData ,
4. UIBackgroundFetchResultFailed 
5. } UIBackgroundFetchResult;
1. const NSTimeInterval  UIApplicationBackgroundFetchIntervalMinimum ;
2. const NSTimeInterval  UIApplicationBackgroundFetchIntervalNever;
1. typedef enum : NSUInteger  {
2. UIBackgroundRefreshStatusRestricted ,
3. UIBackgroundRefreshStatusDenied ,
4. UIBackgroundRefreshStatusAvailable 
5. } UIBackgroundRefreshStatus;
1. typedef enum : NSInteger  {
2. UIInterfaceOrientationUnknown             = UIDeviceOrientationUnknown ,
3. UIInterfaceOrientationPortrait            = UIDeviceOrientationPortrait ,
4. UIInterfaceOrientationPortraitUpsideDown  = UIDeviceOrientationPortraitUpsideDown ,
5. UIInterfaceOrientationLandscapeLeft       = UIDeviceOrientationLandscapeRight ,
6. UIInterfaceOrientationLandscapeRight      = UIDeviceOrientationLandscapeLeft 
7. } UIInterfaceOrientation;
1. typedef enum : NSInteger  {
2. UIUserInterfaceLayoutDirectionLeftToRight ,
3. UIUserInterfaceLayoutDirectionRightToLeft ,
4. } UIUserInterfaceLayoutDirection;
1. NSString *const  UIApplicationOpenSettingsURLString;
1. NSString *const  UIApplicationStatusBarOrientationUserInfoKey ;
2. NSString *const  UIApplicationStatusBarFrameUserInfoKey;
1. NSString *const  UIContentSizeCategoryExtraSmall ;
2. NSString *const  UIContentSizeCategorySmall ;
3. NSString *const  UIContentSizeCategoryMedium ;
4. NSString *const  UIContentSizeCategoryLarge ;
5. NSString *const  UIContentSizeCategoryExtraLarge ;
6. NSString *const  UIContentSizeCategoryExtraExtraLarge ;
7. NSString *const  UIContentSizeCategoryExtraExtraExtraLarge;
1. NSString *const  UIContentSizeCategoryAccessibilityMedium ;
2. NSString *const  UIContentSizeCategoryAccessibilityLarge ;
3. NSString *const  UIContentSizeCategoryAccessibilityExtraLarge ;
4. NSString *const  UIContentSizeCategoryAccessibilityExtraExtraLarge ;
5. NSString *const  UIContentSizeCategoryAccessibilityExtraExtraExtraLarge;
1. NSString *const  UIApplicationInvalidInterfaceOrientationException;
通知

 

 

01. UIApplicationBackgroundRefreshStatusDidChangeNotification
02. UIApplicationDidBecomeActiveNotification
03. UIApplicationDidChangeStatusBarFrameNotification
04. UIApplicationDidChangeStatusBarOrientationNotification
05. UIApplicationDidEnterBackgroundNotification
06. UIApplicationDidFinishLaunchingNotification
07. UIApplicationDidReceiveMemoryWarningNotification
08. UIApplicationProtectedDataDidBecomeAvailable
09. UIApplicationProtectedDataWillBecomeUnavailable
10. UIApplicationSignificantTimeChangeNotification
11. UIApplicationUserDidTakeScreenshotNotification
12. UIApplicationWillChangeStatusBarOrientationNotification
13. UIApplicationWillChangeStatusBarFrameNotification
14. UIApplicationWillEnterForegroundNotification
15. UIApplicationWillResignActiveNotification
16. UIApplicationWillTerminateNotification
17. UIContentSizeCategoryDidChangeNotification

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值