首页 技术 正文
技术 2022年11月12日
0 收藏 623 点赞 5,085 浏览 2039 个字

  1、UIApplication 是 iPhone 应用程序的开始并且负责初始化并显示 UIWindow,并负责加载应用程序的第一个 UIView 到 UIWindow 窗体中。

  UIApplication 的另一个任务是帮助管理应用程序的生命周期,而 UIApplication 通过一个名字为 UIApplicationDelegate 的代理类来履行这个任务。

  尽管 UIApplication 会负责接收事件,而 UIApplicationDelegate 则决定应用程序如何去响应这些事件,UIApplicationDelegate 可以处理的事件包括应用程序的生命周期事件(比如程序启动和关闭)、系统事件(比如来电、记事项警 告)。

  Application 是一个单例对象

  iOS程序创建的第一个对象就是UIApplication对象

  通过[UIApplication sharedApplication]可以获得这个单例对象

UIApplication

UIApplication

2、默认创建一个single模板时,系统自动创建了一个UIApplication的对象

UIApplication

这里的nil其实是@”UIApplication”,在UIApplicationMain中,同时又设置了application的代理:@”AppDelegate”

 // argc:系统传入参数的个数
// argv:系统传入参数的值的列表
// principalClassName:传入主要的类名
// 第四个参数表示:给应用程序"application"指定一个代理对象
return UIApplicationMain(argc, argv, @"UIApplication", @"AppDelegate");

应用程序启动之后,先创建Application,再创建它的代理AppDelegate,之后创建UIwindow,再创建控制器,创建控制器的view,然后将控制器的view添加到UIWindow上。

3.UIApplication常用属性:

1-applicationIconBadgeNumber设置应用图标右上角的提示数字

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
UIApplication *app = [UIApplication sharedApplication]; /**
iOS8.0之后通知消息要进行注册
set to 0 to hide. default is 0. In iOS 8.0 and later, your application must register for user notifications using -[UIApplication registerUserNotificationSettings:] before being able to set the icon badge.
*/
if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0){
//注册
UIUserNotificationSettings *setting = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge categories:nil]; [app registerUserNotificationSettings:setting];
}
app.applicationIconBadgeNumber = ;}

UIApplication

2-设置应用联网状态

@property(nonatomic,getter=isNetworkActivityIndicatorVisible) BOOL networkActivityIndicatorVisible __TVOS_PROHIBITED; // showing network spinning gear in status bar. default is NO

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
UIApplication *app = [UIApplication sharedApplication]; app.networkActivityIndicatorVisible = YES;
}

UIApplication

4、常用方法

打开URL

– (BOOL)openURL:(NSURL*)url NS_EXTENSION_UNAVAILABLE_IOS(“”);

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
UIApplication *app = [UIApplication sharedApplication]; NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];
[app openURL:url];
}

UIApplication

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,489
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,904
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,737
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,490
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,128
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,290