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 转自:http://www.open-open.com/lib/view/open1420634129218.html
UIApplication详解的更多相关文章
- 【转】iOS UIApplication详解
1.状态栏UIStateBar的设置是在UIApplication里面设置的,它包含4中风格 2. - (void)beginIgnoringInteractionEvents; (void)endI ...
- iOS之UIApplication详解
UIApplication对象特点: 特点1: UIApplication对象是应用程序的象征,一个UIApplication对象就代表一个应用程序,而且是单例的.(用来封装整个应用程序的一个对象, ...
- UIApplication详解再解-备
每个app有且只有一个UIApplication对象,当程序启动的时候通过调用UIApplicationMain方法得到的.可以通过sharedApplication方法得到. UIApplicati ...
- iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem
http://blog.csdn.net/totogo2010/article/details/7681879 1.UINavigationController导航控制器如何使用 UINavigati ...
- 详解CALayer 和 UIView的区别和联系
详解CALayer 和 UIView的区别和联系 前言 前面发了一篇iOS 面试的文章,在说到 UIView 和 CALayer 的区别和联系的时候,被喵神指出没有切中要点,所以这里就 CALay ...
- UINavigationController详解一(转)UIBarButtonItem
本文出自:http://www.cnblogs.com/smileEvday/archive/2012/05/14/2495153.html 特别感谢. 1.UINavigationControlle ...
- (转)iOS应用程序生命周期(前后台切换,应用的各种状态)详解
原文:http://blog.csdn.net/totogo2010/article/details/8048652 iOS应用程序生命周期(前后台切换,应用的各种状态)详解 分类: ...
- iOS开发——实用技术OC篇&事件处理详解
事件处理详解 一:事件处理 事件处理常见属性: 事件类型 @property(nonatomic,readonly) UIEventType type; @property(nonatomic ...
- iOS开发——多线程OC篇&多线程详解
多线程详解 前面介绍了多线程的各种方式及其使用,这里补一点关于多线程的概念及相关技巧与使用,相信前面不懂的地方看了这里之后你就对多线程基本上没有什么问题了! 1——首先ios开发多线程中必须了解的概念 ...
随机推荐
- -[NSBundle initWithURL:]: nil URL argument'
今天早上同事突然跟我说趣拍的SDK不能用了,一调用就crash,我一听就纳了闷了,原来好好的啊. 然后就开始查呗,马上就要上线了,不搞好,老大会不会杀了我... 搞个全局断点,就停在了一堆我看不懂的界 ...
- 微信小程序-基础内容组件
icon 图标 示例: <view class="group"> <block wx:for="{{iconSize}}"> <i ...
- nginx基本配置和参数说明
#运行用户user nobody;#启动进程,通常设置成和cpu的数量相等worker_processes 1; #全局错误日志及PID文件#error_log logs/error.log;#err ...
- 【Android 疑难杂症1】android.content.ActivityNotFoundException: Unable to find explicit activity class
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.cnote ...
- WPF的学习笔记(1) -- (积累自2016年5月1日 至 2016年6月1日)
敬告读者:因为是事件驱动模式的高速学习,高速学习意味着,不系统,不科学,不合逻辑,不一定正确.所以要是有不对的地方,页面下面留言给我,跪谢! 背景介绍: 最近在公司的开发工作中,接手了从别的公司交代过 ...
- AngularJS小知识点一
AngularJS是由谷歌公司及一个由开发者组成的个人社区共同打造.其主要优势在于帮助使用者在web应用程序中实现必要的动态视图.它是通过原生的MVC(模型-视图-控制器)功能来增强HTML. PS: ...
- Linux与user和group相关文件分析
/etc/passwd LOGNAME:PASSWORD::UID:GID:USERINFO:HOME:SHELL 注册名:口令:用户标识号:组标识号:用户名:用户主目录:命令解释程序 ()注册名(l ...
- leveldb 学习。
1)大概浏览了leveldb文档的介绍.本想逐步看代码,想想还是自己先实现一个看看如何改进. 2)完成了一个非常丑陋的初版,但是还是比初初版有进步. 3)key value的数据库,不允许有key重复 ...
- c++程序判断系统是Linux还是Windows
用C++来实现,本来想了很多,后来越写越烂,而且结果总是不尽人意,干脆这样子好了: int main() { int judge = system("cls"); ) cout & ...
- springmvc 用注解方式添加事务不生效解决方法
springmvc 事务注册有很多种方法,在此我只mark 用注解方式添加transaction不生效的解决办法. springmvc 注解方法添加事务步骤: 1.在 spring的 root-con ...