Coder Social home page Coder Social logo

maksimkurpa / deeplinkshandler Goto Github PK

View Code? Open in Web Editor NEW
7.0 3.0 1.0 34 KB

DeepLinksHandler is the easiest way to handle internal and external URLs in your project!

License: MIT License

Ruby 7.58% Objective-C 92.42%
nsurl url handler deeplink deeplinks

deeplinkshandler's Introduction

DeepLinksHandler

DeepLinksHandler is the easiest way to handle internal and external URLs in your project!

Demo

I've provided a handful of demos in the bundled example project. To get them to work, you must first install project dependancies with CocoaPods by running:

pod install

Installation

Use the awesome CocoaPods to add DeepLinksHandler to your project:

pod 'DeepLinksHandler'

Usage

For complience with type of style, use URLs with format:

deeplinkshandler://inapp_am?type=subscription&productID=com.examplellc.dlh.7days

where:

scheme - deeplinkshandler, host - inapp_am, query - type=subscription&productID=com.examplellc.dlh.7days

If you don't need to configurate а complexed behavior, you can use URL without query:

deeplinkshandler://show_subscription_screen

Version 1.0.0 - 1.1.0

One special case - handle external URLs when app isn't launched.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    NSURL *url = launchOptions[UIApplicationLaunchOptionsURLKey];
    if (url) {
        [DeepLinksHandler handleURL:url withBlock:^(NSURL *url) {
            NSLog(@"Your deelpink is handled");
        }];
        // this 'dispatch_after' necessary to handle your block after swizzling, which happens after [UIApplication sharedApplication] != nil
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [application openURL:url options:@{} completionHandler:nil];
        });
    }
    return YES;
}

In all cases of usage you should set your handle block for special URl before calling its from sowewhere.

!!!Notice: Only the last sent block for a unique URL will be executed.

static NSString * const kTestHandleURL = @"testurl://viewcontroller?title=ExampleAlert&description=ExampleDescriptionAlert";

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [DeepLinksHandler handleURL:[NSURL URLWithString:kTestHandleURL] withBlock:^(NSURL *url) {
        
        NSString *title = nil;
        NSString *description = nil;
        for (NSURLQueryItem *item in [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:YES].queryItems)
        {
            if ([item.name isEqualToString:@"title"])
                title = item.value;
            else if ([item.name isEqualToString:@"description"])
                description = item.value;
        }
        if (title && description) {
            [[[UIAlertView alloc] initWithTitle:title message:description delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles: nil] show];
        }
    }];
}

- (IBAction)buttonAction:(id)sender {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:kTestHandleURL] options:@{} completionHandler:nil];
}

@end

You have ability to control calling of original methods in UIAplication and UIApplicationDelegate. Just use property isNeedToCallOriginalIMP of DeepLinksHandler.

License

MIT

deeplinkshandler's People

Contributors

maksimkurpa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

carabina

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.