-1

I want to do a inter App communication in between two appliocation with URL Scheme. I have gone through Apple documentation,but won't get so much help.

I have make two projects, in sender there is one method in which i added

{
    UIApplication *ourApplication = [UIApplication sharedApplication];

    NSCharacterSet *set = [NSCharacterSet URLHostAllowedCharacterSet];
    NSString *URLEncodedText = [@"TEST" stringByAddingPercentEncodingWithAllowedCharacters:set];
    NSString *ourPath = [@"readtext://" stringByAppendingString:URLEncodedText];
    NSURL *ourURL = [NSURL URLWithString:ourPath];
    if ([ourApplication canOpenURL:ourURL]) {
        [ourApplication openURL:ourURL];
    }
    else {
    UIAlertController * alert=   [UIAlertController
                                      alertControllerWithTitle:@"Receiver Not Found"
                                      message:@"The Receiver App is not installed"
                                      preferredStyle:UIAlertControllerStyleAlert];

        [self presentViewController:alert animated:YES completion:nil];
        NSLog(@"RECEIVER NOT FOUND");
    }
}

And in Receiver app,added below code to App delegate

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url 
{

    NSCharacterSet *set = [NSCharacterSet URLHostAllowedCharacterSet];
    NSString *text = [[url host] stringByAddingPercentEncodingWithAllowedCharacters:set];

    UIAlertController * alert=   [UIAlertController
                                  alertControllerWithTitle:@"Title"
                                  message:text
                                  preferredStyle:UIAlertControllerStyleAlert];

    [self.window.rootViewController presentViewController:alert animated:YES completion:nil];

    return YES;
}

Also what to add in info.plist and in URL types under Info.

Eiko
  • 25,601
  • 15
  • 56
  • 71
Verma
  • 239
  • 1
  • 5
  • 16
  • Please add a source sample what you tried yourself. – Sebastian May 25 '16 at 06:14
  • I have tried below link,with some of the changes to new ios http://code.tutsplus.com/tutorials/ios-sdk-working-with-url-schemes--mobile-6629 – Verma May 25 '16 at 06:15
  • Add this information to your question (by editing it) and show what you changed. You could easily copy & paste code into the question editor, highlight it and press the { } icon to show it as code. – Sebastian May 25 '16 at 06:17
  • Did some changes,Please check. – Verma May 25 '16 at 06:26

1 Answers1

0

You are add code in .plist file:

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLName</key>
        <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>Scheme_Name</string>
        </array>
    </dict>
</array>

Write code call event:

// use url

[NSURL URLWithString:@"Scheme_Name://"] 

Only See item1:

I am also implement this code in one project with today widget that it is working. Note: Steps replace Scheme_Name in image.

enter image description here

Bhadresh Kathiriya
  • 3,147
  • 2
  • 21
  • 41