How to catch the parameters with branch.io?

自闭症网瘾萝莉.ら 提交于 2019-12-05 05:39:10

问题


I started to use https://branch.io/ in an iOS app.

The problem I am facing now is: how to catch the incoming link with its parameters?

Following the documentation here.

I got to this point, having this link:

http://myapp.app.link/A1bcDEFgHi?XP=315.0,419.0

and my code being:

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
    Branch *branch = [Branch getInstance];
    [branch initSessionWithLaunchOptions:launchOptions 
              andRegisterDeepLinkHandler:^(NSDictionary *params, NSError *error) {
        if (!error && params) {
            NSLog(@"Here is params: %@",params.description); // I need to replace this, with code to get XP!
        }
    }];

    return YES;
}    


- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity
 restorationHandler:(void (^)(NSArray *restorableObjects))restorationHandler
{
    BOOL handledByBranch = [[Branch getInstance] continueUserActivity:userActivity];

    return handledByBranch;
}

Here is what I get in the debugging console:

2016-06-10 11:59:44.407 TheApp[1786:591391] Here is params: {
    "$identity_id" = 2712491317999770034;
    "$one_time_use" = 0;
    "+click_timestamp" = 1465529273;
    "+clicked_branch_link" = 1;
    "+is_first_session" = 0;
    "+match_guaranteed" = 1;
    XP = "315.0,419.0";
    "~creation_source" = "iOS SDK";
    "~id" = 211224109823923327;
}

Now the question is, what is the code to use (inside the app) to get hold of the chunk of data: "315.0,419.0" ?


回答1:


Alex with Branch here: this is a good question, and one that we should probably make more clear in our docs!

When you generate a link (e.g., http://myapp.app.link/A1bcDEFgHi), you can set whatever data parameters you want and you'll get them back in your initSessionWithLaunchOptions() call (as documented here). Your callback data might look something like this:

{
    tags: [ 'tag1', 'tag2' ],
    channel: 'facebook',
    feature: 'dashboard',
    stage: 'new user',
    data: {
        mydata: 'something',
        foo: 'bar',
    }
}

If you append a query to the link URL (e.g., http://myapp.app.link/A1bcDEFgHi?XP=315.0,419.0) we just capture that parameter and pass it through to you:

{
    tags: [ 'tag1', 'tag2' ],
    channel: 'facebook',
    feature: 'dashboard',
    stage: 'new user',
    data: {
        mydata: 'something',
        foo: 'bar',
        XP: '315.0,419.0'
    }
}



回答2:


See this question: Best way to parse URL string to get values for keys?

There are also third party frameworks you can use to handle this. If you're using Cocoapods, go here and search for "Query".


UPDATE

I think you need to set up either URL Schemes or Universal Links in your app.

I have answered a previous question about URL Schemes here and you can checkout branch.io's documentation on Universal Links here


UPDATE 2

In your example output you would access XP as such params[@"XP"] but based on the other answer from Alex you would access it with params[@"data"][@"XP"]

Params is just a dictionary so you access it like you would any other dictionary in iOS.



来源:https://stackoverflow.com/questions/37719046/how-to-catch-the-parameters-with-branch-io

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!