#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
//點擊屏幕會調用該方法
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
UIApplication *app = [UIApplication sharedApplication];
//註冊通知
UIUserNotificationSettings *nitice = [UIUserNotificationSettings
settingsForTypes:UIUserNotificationTypeBadge categories:nil];
[app registerUserNotificationSettings:nitice];
//IconBadgeNumber
app.applicationIconBadgeNumber = 20;
}
@end
運行效果:
#pragma mark - 狀態欄的樣式
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
#pragma mark - 是否隱藏狀態欄(no)
- (BOOL)prefersStatusBarHidden {
return NO;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
//獲取
UIApplication *app = [UIApplication sharedApplication];
//註冊通知
UIUserNotificationSettings *nitice =
[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge categories:nil];
[app registerUserNotificationSettings:nitice];
//IconBadgeNumber
app.applicationIconBadgeNumber = 20;
app.networkActivityIndicatorVisible = YES;
//設置狀態欄
app.statusBarHidden = NO;
app.statusBarStyle = UIStatusBarStyleDefault;
}
打開其他app程序 openURL方法,可以打開其他APP。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// 當應用程序啓動完畢的時候就會調用(系統自動調用)
NSLog(@"%s",__func__);
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
// 即將失去活動狀態的時候調用
NSLog(@"%s",__func__);
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
// 應用程序進入後臺的時候調用
NSLog(@"%s",__func__);
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
/ / 應用程序即將進入前臺的時候調用
NSLog(@"%s",__func__);
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
// 重新激活(能夠和用戶交互)
NSLog(@"%s",__func__);
}
- (void)applicationWillTerminate:(UIApplication *)application {
// 應用程序即將被銷燬的時候會調用該方法
NSLog(@"%s",__func__);
}
應用程序一般有五個狀態:官方文檔app.states
#include<stdio.h>
int main(int argc,char* argv[])
{
printf("hello, world\n");
return 0;
}
#include <QtGui>
int main(int argc,char *argv[]) {
QApplication app(argc,argv);
QLabel label(QString("hellow qt"));
label.show();
app.exec();
}
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char * argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
- argc:argc是命令行總的參數個數
- argv:argv[]是argh個參數,記錄用戶輸入的參數;
- principalClassName:指定應用程序類名(app的象徵),該類必須是UIApplication(或子類),如果爲nil,則用UIApplication類作爲默認值
- delegateClassName:指定應用程序的代理類,UIApplicationDelegate協議中定義的方法,在該類中實現;
#import "AppDelegate.h"
#import "ViewController.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
ViewController *vc = [[ViewController alloc] init];
self.window.rootViewController = vc;
vc.view.backgroundColor = [UIColor redColor];
[self.window makeKeyAndVisible];
return YES;
}