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 ...
随机推荐
- 自定义事件实现不同窗体间的通讯Delphi篇
要实现子窗体与父窗体之间的通讯,有多种方法(比如:重载子窗体的构造函数,将父窗体的引用作为参数传递给子窗体).下面我要介绍的是利用自定义事件的方法,它能够最大程度的避免模块之间的耦合,充分体现面向对象 ...
- Xamarin.Forms DataGrid
控件出处 https://components.xamarin.com/ https://components.xamarin.com/gettingstarted/ZumeroDataGrid/tr ...
- 8.2.1.3 Range Optimization
8.2.1.3 Range Optimization 范围访问方法使用一个单个的索引来检索表记录的自己,包含在一个或者索引值区间. 它可以用于一个单独的部分或者多个部分的索引,下面章节给出了一个详细的 ...
- BZOJ1725: [Usaco2006 Nov]Corn Fields牧场的安排
1725: [Usaco2006 Nov]Corn Fields牧场的安排 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 400 Solved: 290 ...
- HDOJ 1197 Specialized Four-Digit Numbers
Problem Description Find and list all four-digit numbers in decimal notation that have the property ...
- bzoj2019 [Usaco2009 Nov]找工作
Description 奶牛们没钱了,正在找工作.农夫约翰知道后,希望奶牛们四处转转,碰碰运气.而且他还加了一条要求:一头牛在一个城市最多只能赚D(1 <= D <= 1,000)美元,然 ...
- hdu 5389 Zero Escape(记忆化搜索)
Problem Description Zero Escape, is a visual novel adventure video game directed by Kotaro Uchikoshi ...
- (转)最近研究xcodebuild批量打包的一些心得
以前的时候只知道做安卓开发的兄弟挺辛苦的,不但开发的时候要适配一堆的机型,好不容易开发完了还要打一堆不同的包给不同的市场.没想到现在这些市场都开辟iOS市场,于是需要打一堆的包给不同的市场,面对暂时给 ...
- PHP magic_quotes_gpc
大多的PHP程序,都有这样的逻辑: 如果发现php.ini配置为不给GPC变量自动添加转义斜线,则PHP自动为GPC添加转义斜线 但是事实上,这是错误的,因为它改变了GPC变量原来的值. 有这个遗留习 ...
- JavaScript兼容问题汇总[实时更新]
印象笔记链接地址:点我查看 遇到问题不断更新中-- [转载请注明出处-HTML5自由者]