UIApplication详解再解-备

时间:2022-09-05 18:20:48

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

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

获得UIApplication对象

[UIApplication sharedApplication]

获得UIApplicationDelegate对象

[[UIApplication sharedApplication] delegate]

获得UIWindow对象

[[UIApplication sharedApplication] windows];   //UIWindow数组
[[UIApplication sharedApplication] keyWindow]; //UIWindow数组中最后调用makeKeyAndVisible方法的UIWindow对象

控制和处理UIEvent

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

打开URL资源

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];//打开设置界面

配置通知设置

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

后台运行相关

    [[UIApplication sharedApplication] applicationState]; //app状态
[[UIApplication sharedApplication] setMinimumBackgroundFetchInterval:3600]; //设置后台运行时间
NSTimeInterval remainTime = [[UIApplication sharedApplication] backgroundTimeRemaining]; //app后台运行的时间
NSLog(@"remainTIme = %f",remainTime);
int state = [[UIApplication sharedApplication] backgroundRefreshStatus]; //后台刷新的状态
NSLog(@"state = %d",state);
[[UIApplication sharedApplication] beginBackgroundTaskWithName:@"taskOne" expirationHandler:^{
}];
[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
}];
[[UIApplication sharedApplication] endBackgroundTask:1];

远程的控制相关

    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[[UIApplication sharedApplication] endReceivingRemoteControlEvents];

系统的Idle Timer

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

APP样式

    //隐藏状态条
[[UIApplication sharedApplication] setStatusBarHidden:YES];
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
//设置状态条的样式
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
[[UIApplication sharedApplication] statusBarStyle];
//状态条的Frame
[[UIApplication sharedApplication] statusBarFrame];
//网络是否可见
[[UIApplication sharedApplication] isNetworkActivityIndicatorVisible];
//badge数字
[UIApplication sharedApplication].applicationIconBadgeNumber = 2;
//屏幕的方向
[[UIApplication sharedApplication] userInterfaceLayoutDirection];

设置状态条的方向

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:YES];

数据类型

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

通知

UIApplicationBackgroundRefreshStatusDidChangeNotification
UIApplicationDidBecomeActiveNotification
UIApplicationDidChangeStatusBarFrameNotification
UIApplicationDidChangeStatusBarOrientationNotification
UIApplicationDidEnterBackgroundNotification
UIApplicationDidFinishLaunchingNotification
UIApplicationDidReceiveMemoryWarningNotification
UIApplicationProtectedDataDidBecomeAvailable
UIApplicationProtectedDataWillBecomeUnavailable
UIApplicationSignificantTimeChangeNotification
UIApplicationUserDidTakeScreenshotNotification
UIApplicationWillChangeStatusBarOrientationNotification
UIApplicationWillChangeStatusBarFrameNotification
UIApplicationWillEnterForegroundNotification
UIApplicationWillResignActiveNotification
UIApplicationWillTerminateNotification
UIContentSizeCategoryDidChangeNotification

UIApplication详解再解-备的更多相关文章

  1. S&ZeroWidthSpace;Q&ZeroWidthSpace;L&ZeroWidthSpace;&lowbar;&ZeroWidthSpace;S&ZeroWidthSpace;e&ZeroWidthSpace;r&ZeroWidthSpace;v&ZeroWidthSpace;e&ZeroWidthSpace;r&ZeroWidthSpace;&lowbar;&ZeroWidthSpace;2&ZeroWidthSpace;0&ZeroWidthSpace;0&ZeroWidthSpace;8&ZeroWidthSpace;定&ZeroWidthSpace;期&ZeroWidthSpace;自&ZeroWidthSpace;动&ZeroWidthSpace;备&ZeroWidthSpace;份&ZeroWidthSpace;详&ZeroWidthSpace;细&ZeroWidthSpace;图&ZeroWidthSpace;解

    S​Q​L​_​S​e​r​v​e​r​_​2​0​0​8​定​期​自​动​备​份​详​细​图​解 设置自动数据库的定期备份计划. http://wenku.baidu.com/link?url=Tu ...

  2. linux下如何打包压缩?解包解压?&period;tar文件&period;gz文件

    ===文件打包.压缩 ==打包 tar [root@521478.com]# tar -cvf etc1.tar /etc //c创建 v详细 f打包后文件名 [root@521478.com]# t ...

  3. iOS之UIApplication详解

    UIApplication对象特点: 特点1: UIApplication对象是应用程序的象征,一个UIApplication对象就代表一个应用程序,而且是单例的.(用来封装整个应用程序的一个对象, ...

  4. 【转】iOS UIApplication详解

    1.状态栏UIStateBar的设置是在UIApplication里面设置的,它包含4中风格 2. - (void)beginIgnoringInteractionEvents; (void)endI ...

  5. UIApplication详解

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

  6. javascript运行机制详解&colon; 再谈Event Loop&lpar;转&rpar;

    作者: 阮一峰 日期: 2014年10月 8日 一年前,我写了一篇<什么是 Event Loop?>,谈了我对Event Loop的理解. 上个月,我偶然看到了Philip Roberts ...

  7. Jenkins通过FTP上传站点太多文件导致太慢且不稳定,切换为压包上传再解压的思路(asp&period;net)

    在本地先处理好要上传的站点文件之后,可能会因为一些网页切图导致ftp上传不稳定,中断,或者文件占用的问题. 那么换了一种实现思路,要借助jenkins的工具jenkins-cli.jar. 解决思路: ...

  8. 工控安全入门(三)—— 再解S7comm

    之前的文章我们都是在ctf的基础上学习工控协议知识的,显然这样对于S7comm的认识还不够深刻,这次就做一个实战补全,看看S7comm还有哪些值得我们深挖的地方. 本篇是对S7comm的补全和实战,阅 ...

  9. Django ORM中使用update&lowbar;or&lowbar;create功能再解

    以前,我解过这个问题,现在百度搜索,发了像也只能找到我这个帖子. https://www.cnblogs.com/aguncn/p/4922654.html 今天,看了看官方文档,关于这个update ...

随机推荐

  1. SVG中 transform矩阵遇到的兼容性问题

    SVG  transform矩阵遇到的兼容性问题.在chrome.safari.火狐.360极速浏览器上都正常显示的图,在手机端就不行啊!!! 先上图. 图1     PC端浏览器 图2   iPho ...

  2. hibernate的集中持久化方法的区别

    一.预备知识 在所有之前,说明一下,对于hibernate,它的对象有三种状态,transient.persistent.detached 下边是常见的翻译办法: transient:瞬态或者*态 ...

  3. struts2对action中的方法进行输入校验(2)

    struts2输入校验流程: 1.类型转换器对请求參数运行类型转换,并把转换后的值赋给aciton中的属性 2.假设在运行类型转换的过程中出现异常,系统会将异常信息保存到ActionContext, ...

  4. AngularJS 的表单验证

    最近开始学习angularjs,学到表单验证的时候发现有必要学习下大神的好文章: 转:http://www.oschina.net/translate/angularjs-form-validatio ...

  5. C语言的第二次作业

    一.PTA实验作业 题目1. 计算分段函数 本题目要求计算下列分段函数f(x)的值: 1.本题代码 #include<stdio.h> #include<math.h> int ...

  6. 自定义element-ui中的图标

    element-ui图标库图标较少,比如有关于登录页面输入框里的用户名和密码的小图标就没有,这个时候可以自定义图标. <el-input v-model="loginForm.user ...

  7. caffe-ssd需要安装opencv

    https://blog.csdn.net/xiaxiazls/article/details/52039473

  8. Linux系统编程——水平触发和边沿触发

    事件模型 EPOLL事件有两种模型: Edge Triggered (ET) 边缘触发只有数据到来才触发,不管缓存区中是否还有数据. Level Triggered (LT) 水平触发只要有数据都会触 ...

  9. github 遇到Permanently added the RSA host key for IP address &&num;39&semi;192&period;30&period;252&period;128&&num;39&semi; to the list of known hosts问题解决

    刚开始使用github的时候不是很了解,新手一般的都会遇到这个问题Permanently added the RSA host key for IP address '192.30.252.128' ...

  10. ubuntu下objective-c的编译和运行

    ubuntu 下编译objective-c 1.安装编译环境 sudo aptitude install build-essential gobjc gobjc++ gnustep gnustep-d ...