didFinishLaunchingWithOptions

3575 단어
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Description: Executed when the application starts, the application starts the entry. Executed only once when the application starts. The application parameter is used to obtain the state, variables, etc. of the application. It is worth noting that the dictionary parameter: (NSDictionary *) launchOptions, which stores the reason for the program startup. If the user launches directly, there is no data in launchOptions; if it is launched by other applications through openURL:, the object corresponding to UIApplicationLaunchOptionsURLKey is the launch URL (NSURL), and UIApplicationLaunchOptionsSourceApplicationKey corresponds to the bundle ID (NSString) of the launched source application; if notified locally If it is started, UIApplicationLaunchOptionsLocalNotificationKey corresponds to the local notification object (UILocalNotification) for launching the application; if it is started by remote notification, UIApplicationLaunchOptionsRemoteNotificationKey corresponds to the remote notification information userInfo (NSDictionary) for launching the application; other keys are UIApplicationLaunchOptionsAnnotationKey, UIApplicationLaunchOptionsLocationKey, UIApplicationLaunchOptionsNewsstandDownloadsKey. If you want to make some distinctions at startup, you need to do it in the following code. For example: an application can be invoked by some other application (as a sub-application of the application), to achieve single sign-on, it is necessary to make reasonable verification in the place of startup code and skip the login.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{    NSURL *url = [launchOptionsobjectForKey:UIApplicationLaunchOptionsURLKey];    
if(url) {        
    }

    NSString *bundleId = [launchOptionsobjectForKey:UIApplicationLaunchOptionsSourceApplicationKey];  
  if(bundleId) {
    }    UILocalNotification * localNotify = [launchOptionsobjectForKey:UIApplicationLaunchOptionsLocalNotificationKey]; 
   if(localNotify) {    }
    NSDictionary * userInfo = [launchOptionsobjectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];    if(userInfo)  {
    }}
   /**

     *  app ,app kill, , app app,return NO  application: openURL:sourceApplication:annotation:( app )

     */

    if (launchOptions) {

        NSString *appIDF = [launchOptionsobjectForKey:UIApplicationLaunchOptionsSourceApplicationKey];

        if (appIDF && [appIDFisEqualToString:@"com.alipay.iphoneclient"]) {

            returnNO;

        }

    }

#pragma mark-- app url 

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation

{

    NSString *urlStr = [urlabsoluteString];

    //  app app

    if(sourceApplication && [sourceApplicationisEqualToString:@"com.alipay.iphoneclient"]){

        [[AlipaySDKdefaultService] processOrderWithPaymentResult:urlstandbyCallback:^(NSDictionary *resultDic) {

            NSDictionary *dict = @{ALIPayDidCompleteURLKey:urlStr};

            [[NSNotificationCenterdefaultCenter ] postNotificationName:ALIPayFromZFBDidCompleteNotificationobject:resultDic userInfo:dict];

        }];

    }

    returnYES;

}

// 
        [[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(processAliPayResult:)name:ALIPayFromZFBDidCompleteNotificationobject:nil];

좋은 웹페이지 즐겨찾기