Detailed explanation of iOS AppDelegate agent (start, open App, push, notify)
- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(nullable NSDictionary *)launchOptions{
return YES;
}
//App has started- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// openURL:
NSURL *url = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey];
if(url){
}
// bundle ID
NSString *bundleId = [launchOptions objectForKey:UIApplicationLaunchOptionsSourceApplicationKey];
if(bundleId){
}
//
UILocalNotification * localNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if(localNotification){
}
//
NSDictionary * remoteNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if(remoteNotification){
}
return YES;
}
//App is about to enter the foreground- (void)applicationWillResignActive:(UIApplication *)application {
}
//App
- (void)applicationDidBecomeActive:(UIApplication *)application {
}
//App is about to enter the background- (void)applicationWillEnterForeground:(UIApplication *)application {
}
//App has entered the background- (void)applicationDidEnterBackground:(UIApplication *)application {
}
//App is about to exit- (void)applicationWillTerminate:(UIApplication *)application {
}
//App memory warning- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
{
NSLog(@" ");
}
/*This method is called when other applications wake up your application through the url
In addition, you need to add your own url protocol to the plist Step 1: Find "URL types"in Info Step 2: Add a URL identifier, it is recommended to use an anti-domain name (com.jingjin.myApp), URL Schemes (myApp), URL Schemes is the beginning of the URL that wakes up your application.
*/
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
if (!url) {//
return NO;
}
NSLog(@"handleOpenURL: %@", [url absoluteString]);
//
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"myapp://"]]) {
//
return YES;
} else {
return NO;
}
return YES;
}
StatusBar box orientation is about to change- (void)application:(UIApplication*)application willChangeStatusBarOrientation:
(UIInterfaceOrientation)newStatusBarOrientation duration:(NSTimeInterval)duration
{
}
StatusBar box orientation has changed- (void)application:(UIApplication*)application didChangeStatusBarOrientation:(UIInterfaceOrientation)oldStatusBarOrientation{
}
//StatusBar frame coordinates will change- (void)application:(UIApplication*)application willChangeStatusBarFrame:(CGRect)newStatusBarFrame{
}
//StatusBar frame coordinates have changed- (void)application:(UIApplication*)application didChangeSetStatusBarFrame:(CGRect)oldStatusBarFrame{
}
//Execute when the system time changes- (void)applicationSignificantTimeChange:(UIApplication *)application{
}
//Already registered for remote notification- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings{
}
//When the application successfully registers a push service-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *) deviceToken{
NSString *tokenStr = [NSString stringWithFormat:@"%@",deviceToken];
// <>
tokenStr = [tokenStr stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
//
tokenStr = [tokenStr stringByReplacingOccurrencesOfString:@" " withString:@""];
}
//When APS cannot successfully complete the push to the program process-(void) application:(UIApplication *) application didFailToRegisterForRemoteNotificationsWithError:(NSError *) error{
}
//When a running application receives a local notification- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{
}
//The program receives the remote notification- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler{
if (application.applicationState == UIApplicationStateActive) {//
}else if(application.applicationState == UIApplicationStateInactive){//
}
AudioServicesPlaySystemSound(1007);//
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);//
//
NSString *path = [[NSBundle mainBundle] pathForResource:@"message" ofType:@"wav"];
//
SystemSoundID soundID;
NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)filePath, &soundID);
AudioServicesPlaySystemSound(soundID);
//
AudioServicesDisposeSystemSoundID(soundID);
/*
userInfo , :
{
"aps" : {
"alert" : "",
"badge" : 10,//
"sound" : ""//app icon
},
"acme1" : "bar",
"acme2" : 42//
}
*/
}
//- (void)application:(UIApplication *)application handleActionWithIdentifier:(nullable NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo withResponseInfo:(NSDictionary *)responseInfo completionHandler:(void(^)())completionHandler{
}
- (void)application:(UIApplication *)application handleActionWithIdentifier:(nullable NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler{
}
Handling local notifications- (void)application:(UIApplication *)application handleActionWithIdentifier:(nullable NSString *)identifier forLocalNotification:(UILocalNotification *)notification withResponseInfo:(NSDictionary *)responseInfo completionHandler:(void(^)())completionHandler{
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.