UIApplication详解再解-备
每个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详解再解-备的更多相关文章
- SQL_Server_2008定期自动备份详细图解
SQL_Server_2008定期自动备份详细图解 设置自动数据库的定期备份计划. http://wenku.baidu.com/link?url=Tu ...
- linux下如何打包压缩?解包解压?.tar文件.gz文件
===文件打包.压缩 ==打包 tar [root@521478.com]# tar -cvf etc1.tar /etc //c创建 v详细 f打包后文件名 [root@521478.com]# t ...
- iOS之UIApplication详解
UIApplication对象特点: 特点1: UIApplication对象是应用程序的象征,一个UIApplication对象就代表一个应用程序,而且是单例的.(用来封装整个应用程序的一个对象, ...
- 【转】iOS UIApplication详解
1.状态栏UIStateBar的设置是在UIApplication里面设置的,它包含4中风格 2. - (void)beginIgnoringInteractionEvents; (void)endI ...
- UIApplication详解
每个app有且只有一个UIApplication对象,当程序启动的时候通过调用UIApplicationMain方法得到的.可以通过sharedApplication方法得到. UIApplicati ...
- javascript运行机制详解: 再谈Event Loop(转)
作者: 阮一峰 日期: 2014年10月 8日 一年前,我写了一篇<什么是 Event Loop?>,谈了我对Event Loop的理解. 上个月,我偶然看到了Philip Roberts ...
- Jenkins通过FTP上传站点太多文件导致太慢且不稳定,切换为压包上传再解压的思路(asp.net)
在本地先处理好要上传的站点文件之后,可能会因为一些网页切图导致ftp上传不稳定,中断,或者文件占用的问题. 那么换了一种实现思路,要借助jenkins的工具jenkins-cli.jar. 解决思路: ...
- 工控安全入门(三)—— 再解S7comm
之前的文章我们都是在ctf的基础上学习工控协议知识的,显然这样对于S7comm的认识还不够深刻,这次就做一个实战补全,看看S7comm还有哪些值得我们深挖的地方. 本篇是对S7comm的补全和实战,阅 ...
- Django ORM中使用update_or_create功能再解
以前,我解过这个问题,现在百度搜索,发了像也只能找到我这个帖子. https://www.cnblogs.com/aguncn/p/4922654.html 今天,看了看官方文档,关于这个update ...
随机推荐
- VS2008 运行VC\Bin下的link.exe, cl.exe, lib.exe提示找不到mspdb80.dll的解决方法
天在用link.EXE的LIB命令生成用于连接(LINK)使用的lib文件时提示:找不到mspdb80.dll. 原因:Microsoft Visual Studio\VC\Bin\下没有 “msob ...
- opencv 图像仿射变换 计算仿射变换后对应特征点的新坐标 图像旋转、缩放、平移
常常需要最图像进行仿射变换,仿射变换后,我们可能需要将原来图像中的特征点坐标进行重新计算,获得原来图像中例如眼睛瞳孔坐标的新的位置,用于在新得到图像中继续利用瞳孔位置坐标. 仿射变换在:http:// ...
- 【HDOJ】4544 湫湫系列故事——消灭兔子
贪心,普通贪心两层循环TLE了,然后用优先级队列维护内层. #include <iostream> #include <cstdio> #include <cstring ...
- HDU_2013——蟠桃记,反向推理
Problem Description 喜欢西游记的同学肯定都知道悟空偷吃蟠桃的故事,你们一定都觉得这猴子太闹腾了,其实你们是有所不知:悟空是在研究一个数学问题!什么问题?他研究的问题是蟠桃一共有多少 ...
- 批量将文件转换为UTF-8无BOM格式
最近有一个项目需要迁移,要把文件全部转换成utf8格式的,本来想用python,后来听说PowerShell很是强大,就试着用了一下,果然好用啊! $list = Get-ChildItem .\ - ...
- 关于本学期西南交通大学ACM-ICPC校集训队 训练计划(Beta 1.0)
在第十周新秀杯之后,从第十一周起的训练计划如下: 1.十一周的周一至周五进行ACM校集训队申请.申请方式从2014年11月17日0:00开始,发送申请者的姓名.学号.专业.电话.QQ以及大学(针对大一 ...
- i++与++i的区别,使用实例说明
/** * 类名:TEST.java<br> * <p> * 功能:i++与++i的区别,使用实例说明 * </p> * * @Author:<a href= ...
- [React Testing] Reusing test boilerplate
Setting up a shallow renderer for each test can be redundant, especially when trying to write simila ...
- Hadoop 开源调度系统zeus(二)
紧跟之前Hadoop 开源调度系统zeus(一) 本节主要介绍一下zeus的架构: 先给一个zeus的架构图 无论Master还是Worker都有一套WEB UI,无论从哪个上面去看,看到的结果都是一 ...
- Java调用天气Webservice的小应用
废话不多说,直接贴代码: CityReq.java package com.weather; import javax.xml.bind.annotation.XmlElement; import j ...