UIApplication详解

来源:互联网 发布:淘宝不能延长收货 编辑:程序博客网 时间:2024/05/19 22:50

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

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

获得UIApplication对象

 

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

 

 

view sourceprint?
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.}
view sourceprint?
1.[[UIApplication sharedApplication] beginIgnoringInteractionEvents]; //开始忽略Event
2.//...中间调用动画等操作
3.[[UIApplication sharedApplication] endIgnoringInteractionEvents];   //结束忽略Event
view sourceprint?
1.[UIApplication sharedApplication].applicationSupportsShakeToEdit = YES;  //晃动是否有撤销或者重做动作
打开URL资源

 

 

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

 

 

view sourceprint?
1.UIUserNotificationType  types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
2.UIUserNotificationSettings  *mySettings  = [UIUserNotificationSettings settingsForTypes:types categories:nil];
3.[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings]; //注册远程推送通知
view sourceprint?
1.[[UIApplication sharedApplication] registerForRemoteNotifications];//注册
2.[[UIApplication sharedApplication] unregisterForRemoteNotifications];//注销
view sourceprint?
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]; //注册通知
view sourceprint?
1.[[UIApplication sharedApplication] presentLocalNotificationNow:localNotif]; //立即通知
2.[[UIApplication sharedApplication] cancelAllLocalNotifications]; //取消所有通知
3.[[UIApplication sharedApplication] cancelLocalNotification:localNotif]; //取消特定的通知
4. 
5.NSArray *arr = [[UIApplication sharedApplication] scheduledLocalNotifications];  //所有的通知
后台运行相关

 

 

view sourceprint?
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];
远程的控制相关

 

 

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

 

 

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

 

 

view sourceprint?
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];
设置状态条的方向

 

 

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

 

 

view sourceprint?
1.UIBackgroundTaskIdentifier : Int
view sourceprint?
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;
view sourceprint?
1.typedef enum : NSInteger {
2.UIStatusBarStyleDefault,
3.UIStatusBarStyleLightContent,
4. 
5.UIStatusBarStyleBlackTranslucent,
6.UIStatusBarStyleBlackOpaque
7.} UIStatusBarStyle;
view sourceprint?
1.typedef enum : NSInteger {
2.UIStatusBarAnimationNone,
3.UIStatusBarAnimationFade,
4.UIStatusBarAnimationSlide,
5.} UIStatusBarAnimation;
view sourceprint?
1.typedef enum : NSInteger  {
2.UIApplicationStateActive ,
3.UIApplicationStateInactive ,
4.UIApplicationStateBackground 
5.} UIApplicationState;
view sourceprint?
1.const UIBackgroundTaskIdentifier  UIBackgroundTaskInvalid ;
2.const NSTimeInterval  UIMinimumKeepAliveTimeout;
view sourceprint?
1.typedef enum : NSUInteger  {
2.UIBackgroundFetchResultNewData ,
3.UIBackgroundFetchResultNoData ,
4.UIBackgroundFetchResultFailed 
5.} UIBackgroundFetchResult;
view sourceprint?
1.const NSTimeInterval  UIApplicationBackgroundFetchIntervalMinimum ;
2.const NSTimeInterval  UIApplicationBackgroundFetchIntervalNever;
view sourceprint?
1.typedef enum : NSUInteger  {
2.UIBackgroundRefreshStatusRestricted ,
3.UIBackgroundRefreshStatusDenied ,
4.UIBackgroundRefreshStatusAvailable 
5.} UIBackgroundRefreshStatus;
view sourceprint?
1.typedef enum : NSInteger  {
2.UIInterfaceOrientationUnknown             = UIDeviceOrientationUnknown ,
3.UIInterfaceOrientationPortrait            = UIDeviceOrientationPortrait ,
4.UIInterfaceOrientationPortraitUpsideDown  = UIDeviceOrientationPortraitUpsideDown ,
5.UIInterfaceOrientationLandscapeLeft       = UIDeviceOrientationLandscapeRight ,
6.UIInterfaceOrientationLandscapeRight      = UIDeviceOrientationLandscapeLeft 
7.} UIInterfaceOrientation;
view sourceprint?
1.typedef enum : NSInteger  {
2.UIUserInterfaceLayoutDirectionLeftToRight ,
3.UIUserInterfaceLayoutDirectionRightToLeft ,
4.} UIUserInterfaceLayoutDirection;
view sourceprint?
1.NSString *const  UIApplicationOpenSettingsURLString;
view sourceprint?
1.NSString *const  UIApplicationStatusBarOrientationUserInfoKey ;
2.NSString *const  UIApplicationStatusBarFrameUserInfoKey;
view sourceprint?
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;
view sourceprint?
1.NSString *const  UIContentSizeCategoryAccessibilityMedium ;
2.NSString *const  UIContentSizeCategoryAccessibilityLarge ;
3.NSString *const  UIContentSizeCategoryAccessibilityExtraLarge ;
4.NSString *const  UIContentSizeCategoryAccessibilityExtraExtraLarge ;
5.NSString *const  UIContentSizeCategoryAccessibilityExtraExtraExtraLarge;
view sourceprint?
1.NSString *const  UIApplicationInvalidInterfaceOrientationException;
通知

 

 

view sourceprint?
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