Detailed explanation of iOS AppDelegate agent (start, open App, push, notify)

6744 단어
App is about to start
- (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{


}

좋은 웹페이지 즐겨찾기