文档章节

UIApplication相关属性

落叶知秋殇
 落叶知秋殇
发布于 2016/06/23 09:43
字数 794
阅读 39
收藏 0

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;  //晃动是否有撤销或者重做动作

UIApplication有个功能十分强大的openURL:方法

- (BOOL)openURL:(NSURL*)url;

openURL:方法的部分功能有

打电话  UIApplication *app = [UIApplicationsharedApplication]; [app openURL:[NSURLURLWithString:@"tel://10086"]];

发短信  [app openURL:[NSURLURLWithString:@"sms://10086"]];

发邮件  [app openURL:[NSURLURLWithString:@"mailto://12345@qq.com"]];

打开一个网页资源 [app openURL:[NSURLURLWithString:@"http://ios.itcast.cn"]];

打开其他app程序   openURL方法,可以打开其他APP。

配置通知设置

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

© 著作权归作者所有

上一篇: 常用的属性
落叶知秋殇
粉丝 0
博文 19
码字总数 5068
作品 0
合肥
iOS工程师
私信 提问
IOS开发之视图控制器view的生命周期

#import "DiscoverViewController.h" @interface DiscoverViewController () @end @implementation DiscoverViewController //视图控制器view的生命周期的方法都是自动调用的 //注意:重写vie......

鹿微微鹿
2016/04/13
39
0
iOS程序的完整启动过程及原理

PY为我的前缀名 1.先执行main函数,main内部会调用UIApplicationMain函数2.UIApplicationMain函数里面做了什么事情:1> 创建UIApplication对象2> 创建UIApplication的delegate对象-----PYAp...

哥特复心
2013/12/09
4.3K
1
iOS程序启动原理

iOS程序启动原理 发表于1年前(2014-05-25 11:00) 阅读(1183) | 评论(0) 5人收藏此文章, 取消收藏 赞0 9月19日成都 OSC 源创会正在报名,送机械键盘和开源无码内裤 摘要 本文介绍iOS程序中...

法斗斗
2015/09/02
147
0
IOS开发之UITextField

#import "AppDelegate.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )l......

鹿微微鹿
2016/04/12
31
0
iOS程序的完整启动过程及原理

PY为我的前缀名 1.先执行main函数,main内部会调用UIApplicationMain函数 2.UIApplicationMain函数里面做了什么事情: 1> 创建UIApplication对象 2> 创建UIApplication的delegate对象—–PYA...

sundy_ly
2014/01/10
87
0

没有更多内容

加载失败,请刷新页面

加载更多

SpringBoot中 集成 redisTemplate 对 Redis 的操作(二)

SpringBoot中 集成 redisTemplate 对 Redis 的操作(二) List 类型的操作 1、 向列表左侧添加数据 Long leftPush = redisTemplate.opsForList().leftPush("name", name); 2、 向列表右......

TcWong
今天
7
0
排序––快速排序(二)

根据排序––快速排序(一)的描述,现准备写一个快速排序的主体框架: 1、首先需要设置一个枢轴元素即setPivot(int i); 2、然后需要与枢轴元素进行比较即int comparePivot(int j); 3、最后...

FAT_mt
昨天
4
0
mysql概览

学习知识,首先要有一个总体的认识。以下为mysql概览 1-架构图 2-Detail csdn |简书 | 头条 | SegmentFault 思否 | 掘金 | 开源中国 |

程序员深夜写bug
昨天
10
0
golang微服务框架go-micro 入门笔记2.2 micro工具之微应用利器micro web

micro web micro 功能非常强大,本文将详细阐述micro web 命令行的功能 阅读本文前你可能需要进行如下知识储备 golang分布式微服务框架go-micro 入门笔记1:搭建go-micro环境, golang微服务框架...

非正式解决方案
昨天
9
0
前端——使用base64编码在页面嵌入图片

因为页面中插入一个图片都要写明图片的路径——相对路径或者绝对路径。而除了具体的网站图片的图片地址,如果是在自己电脑文件夹里的图片,当我们的HTML文件在别人电脑上打开的时候图片则由于...

被毒打的程序猿
昨天
9
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部