1

I am using the below lines to transfer and open the ios app from other ios application.

    NSURL *url = [[NSURL alloc]initWithString:@"test2://"];
    NSMutableDictionary *tempDict = [[NSMutableDictionary alloc]init];  
    [tempDict setObject:@"companyURL" forKey:@"company"];   
    [tempDict setObject:@"https://companyURL" forKey:@"cburl"];   
    [tempDict setObject:@"AccessToken" forKey:@"AccessToken"];   
    NSDictionary *options = @{UIApplicationOpenURLOptionsAnnotationKey : tempDict};
    [[UIApplication sharedApplication] openURL:url options:options completionHandler:^(BOOL success) {
    if (success) {
   NSLog(@"Opened url");
     }}    
];

The "Test2" application has opened successfully but cannot retrieve the dictionary(options) value. Please guide me.

I have referred some other blogs, They are passing the data in URL itself. But How to pass the data in options?

In the Test2 application, I am using below code to retrieve the data,

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {
  NSLog(@"URL %@",url);
  NSLog(@"Option %@",options);

  return YES;
}

It shows the only these two values in the option

 Option {
    UIApplicationOpenURLOptionsOpenInPlaceKey = 0;
    UIApplicationOpenURLOptionsSourceApplicationKey = "com.test.testApplicaton";
}
Finder
  • 8,259
  • 8
  • 39
  • 54

1 Answers1

0

pass what ever the needed data as parameters.

//For Calling

NSString *urlS = @"customUrlScheme://name=shehan&age=27";
    NSURL *url = [[NSURL alloc]initWithString:urlS];
    UIApplication *applicaton = [UIApplication sharedApplication];
    [applicaton openURL:url options:options completionHandler:^(BOOL success) {
        NSLog(@"Success");
    }];

//For receiving

-(BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options{

    NSString *vc = [url description];

    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithCapacity:6];
   NSArray *pairs = [[url debugDescription] componentsSeparatedByString:@"://"];
pairs = [pairs[1] componentsSeparatedByString:@"&"];

    for (NSString *pair in pairs) {
        NSArray *elements = [pair componentsSeparatedByString:@"="];
        NSString *key = [[elements objectAtIndex:0] stringByRemovingPercentEncoding];
        NSString *val = [[elements objectAtIndex:1] stringByRemovingPercentEncoding];

        [dict setObject:val forKey:key];
    }

    NSString *name = [dict valueForKey:@"name"];
    NSString *age = [dict valueForKey:@"age"];
    NSLog(name);
    NSLog(age);

    return true;
}
  • Yes. We can use this way to pass the data. But my question here, How to pass(in options) the data as a dictionary without appending the value in the url. – Finder Nov 19 '18 at 06:30