{"__v":16,"_id":"561c64ffbe5fb20d00077748","category":{"project":"55e67aaa9cc7c62b00c4a1ea","version":"55e67aab9cc7c62b00c4a1ed","_id":"589b8e1fdbb7cd190026732c","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2017-02-08T21:31:11.878Z","from_sync":false,"order":6,"slug":"advanced-techniques","title":"Advanced Techniques"},"parentDoc":null,"project":"55e67aaa9cc7c62b00c4a1ea","user":"55d29988486de50d00327118","version":{"__v":10,"_id":"55e67aab9cc7c62b00c4a1ed","project":"55e67aaa9cc7c62b00c4a1ea","createdAt":"2015-09-02T04:27:23.612Z","releaseDate":"2015-09-02T04:27:23.612Z","categories":["55e67aac9cc7c62b00c4a1ee","55e67b5556007d23005fee7d","55e67b5dde6fef23009480ca","55e680efde6fef23009480db","55e6829485a9741900314e99","561c61b4ad272c0d00a892df","586c014c0abf1d0f000d04d4","58991d2ad207df0f0002186b","589b8e1fdbb7cd190026732c","58b8ca5e3265d70f001788d4"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":["564a77fcefeab10d00630fe9"],"next":{"pages":[],"description":""},"createdAt":"2015-10-13T01:57:19.323Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":0,"body":"Deep linking is a powerful technique that, with some preparation by a developer, can lead to a very advanced form of messaging. Deep linking is a process by where a URL is opened by your app, and then in response your app is opened to a specific screen. You might be familiar with deep linking on Facebook, where URIs are in the form of `fb://something`. In deep links, the protocol is the name of your app (or similar) and your app defines the routes the URL maps to. \n\nCarnival supports deep links with URL type messages. You can include your deep link URL (for your app scheme) in the URL field of a link message and it will trigger your deep links. However, if you want to use push messages only, then this is achieved instead with [Key-Value Payloads](doc:key-value-payloads).\n\n# iOS\nOn iOS deep linking occurs with Custom URL Schemes. There are 3 main parts to this. \n\n 1. Define your URL Scheme in you app's Info.plist\n 2. Implement `-application:openURL:options:` in your app delegate\n 3. Inside this, parse the URL for any parameters, initialize the correct view controllers and present them.  \n\nFor implementation details on Custom URL Schemes, have a look in the [iOS Developer Library](https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/Inter-AppCommunication/Inter-AppCommunication.html#//apple_ref/doc/uid/TP40007072-CH6-SW10) on Apple's website. \n\nHere's an example using a simple url scheme: `myapp://?screen=new_post`. \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"\\t//In your App Delegate\\n\\t- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(nonnull NSDictionary<NSString *,id> *)options {\\n\\t\\tNSDictionary *params = [self queryParamsFromURL:url];\\n\\t    if ([[UIApplication objectForKey::::at:::\\\"screens\\\"] isEqualToString:@\\\"new_post\\\"]) {\\n\\t    \\tNewPostViewController *npViewController = [NewPostViewController alloc] init];\\n\\t    \\t[self.window.rootViewController presentViewController:npViewController];\\n\\t\\t} // else if other supported views, keys and values here\\n\\t\\treturn YES;\\n}\\n\\n- (NSDictionary *)queryParamsFromURL:(NSURL *)url {\\n\\t    NSArray *queryComponents = [[url query] componentsSeparatedByString:@\\\"&\\\"];\\n\\t    \\n\\t    NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithCapacity:[queryComponents count]];\\n\\t    \\n\\t    for (NSString *queryComponent in queryComponents) {\\n\\t        NSArray *paramComponents = [queryComponent componentsSeparatedByString:@\\\"=\\\"];\\n\\t        \\n\\t        id object = nil;\\n\\t        \\n\\t        if ([paramComponents count] > 1) {\\n\\t            object = [paramComponents[1] stringByReplacingPercentEscapesUsingEncoding:NSISOLatin1StringEncoding];\\n\\t        }\\n\\t        else {\\n\\t            object = [NSNull null];\\n\\t        }\\n\\t        \\n\\t        NSString *key = [paramComponents[0] stringByReplacingPercentEscapesUsingEncoding:NSISOLatin1StringEncoding];\\n\\t        \\n\\t        [parameters setObject:object forKey:key];\\n\\t    }\\n\\t    \\n\\t    return parameters;\\n}\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nNote: If the deep link comes from the Carnival Message Stream, you may want to dismiss the message stream before navigating to your desired view.\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"iOS 9+ Support\",\n  \"body\": \"iOS 9 Requires an additional key to previously, where you need to define an array of schemes using the [LSApplicationQueriesSchemes key](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/#//apple_ref/occ/instm/UIApplication/canOpenURL:).\"\n}\n[/block]\n# Android\n\nOn Android, deep linking occurs with the use of Intent Filters. There are 3 main parts to this. \n\nFirst, define your Intent Filter in your app's manifest file, with the `<data>` element filled out. This must be associated with an activity, typically the root. \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<activity android:name=\\\".MyActivity\\\">\\n\\t<intent-filter>\\n\\t\\t<action android:name=\\\"android.intent.action.VIEW\\\" />\\n\\t\\t<category android:name=\\\"android.intent.category.DEFAULT\\\" />\\n\\t\\t<category android:name=\\\"android.intent.category.BROWSABLE\\\" />\\n\\t\\t<data android:scheme=\\\"myapp\\\"/>\\n\\t</intent-filter>\\n</activity>\",\n      \"language\": \"xml\"\n    }\n  ]\n}\n[/block]\nThen, read the `Intent` that was used to start your application in the `onCreate` method of your activity. If your application is already running, the Intent will be sent to the `onNewIntent(Intent)` method of the receiving Activity.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Intent intent = getIntent();\\nif (Intent.ACTION_VIEW.equals(intent.getAction())) {\\n\\tUri uri = intent.getData();\\n\\tString valueOne = uri.getQueryParameter(\\\"keyOne\\\");\\n\\tString valueTwo = uri.getQueryParameter(\\\"keyTwo\\\");\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nFinally, inside this, parse the URL for any parameters, configure your activity respectively.\n\nFor implementation details on Intent Filters, have a look in the [Android Developer Library](http://developer.android.com/guide/components/intents-filters.html) on Google's website.\n\n# Triggering with Carnival\n\nOnce implemented by a developer, deep linking URLs can be sent like any other link message. Simply send the link to your audience, and once the user taps on the link, they'll be directed to the correct part of the app. \n\nIf you want to use deep linking without messages (just using a plain push), then this can be achieved with [Key-Value Payloads](doc:key-value-payloads).","excerpt":"Opening specific sections of your app right from Carnival Messages","slug":"deep-linking","type":"basic","title":"Deep Linking"}

Deep Linking

Opening specific sections of your app right from Carnival Messages

Deep linking is a powerful technique that, with some preparation by a developer, can lead to a very advanced form of messaging. Deep linking is a process by where a URL is opened by your app, and then in response your app is opened to a specific screen. You might be familiar with deep linking on Facebook, where URIs are in the form of `fb://something`. In deep links, the protocol is the name of your app (or similar) and your app defines the routes the URL maps to. Carnival supports deep links with URL type messages. You can include your deep link URL (for your app scheme) in the URL field of a link message and it will trigger your deep links. However, if you want to use push messages only, then this is achieved instead with [Key-Value Payloads](doc:key-value-payloads). # iOS On iOS deep linking occurs with Custom URL Schemes. There are 3 main parts to this. 1. Define your URL Scheme in you app's Info.plist 2. Implement `-application:openURL:options:` in your app delegate 3. Inside this, parse the URL for any parameters, initialize the correct view controllers and present them. For implementation details on Custom URL Schemes, have a look in the [iOS Developer Library](https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/Inter-AppCommunication/Inter-AppCommunication.html#//apple_ref/doc/uid/TP40007072-CH6-SW10) on Apple's website. Here's an example using a simple url scheme: `myapp://?screen=new_post`. [block:code] { "codes": [ { "code": "\t//In your App Delegate\n\t- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(nonnull NSDictionary<NSString *,id> *)options {\n\t\tNSDictionary *params = [self queryParamsFromURL:url];\n\t if ([[UIApplication objectForKey:@\"screens\"] isEqualToString:@\"new_post\"]) {\n\t \tNewPostViewController *npViewController = [NewPostViewController alloc] init];\n\t \t[self.window.rootViewController presentViewController:npViewController];\n\t\t} // else if other supported views, keys and values here\n\t\treturn YES;\n}\n\n- (NSDictionary *)queryParamsFromURL:(NSURL *)url {\n\t NSArray *queryComponents = [[url query] componentsSeparatedByString:@\"&\"];\n\t \n\t NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithCapacity:[queryComponents count]];\n\t \n\t for (NSString *queryComponent in queryComponents) {\n\t NSArray *paramComponents = [queryComponent componentsSeparatedByString:@\"=\"];\n\t \n\t id object = nil;\n\t \n\t if ([paramComponents count] > 1) {\n\t object = [paramComponents[1] stringByReplacingPercentEscapesUsingEncoding:NSISOLatin1StringEncoding];\n\t }\n\t else {\n\t object = [NSNull null];\n\t }\n\t \n\t NSString *key = [paramComponents[0] stringByReplacingPercentEscapesUsingEncoding:NSISOLatin1StringEncoding];\n\t \n\t [parameters setObject:object forKey:key];\n\t }\n\t \n\t return parameters;\n}", "language": "objectivec" } ] } [/block] Note: If the deep link comes from the Carnival Message Stream, you may want to dismiss the message stream before navigating to your desired view. [block:callout] { "type": "warning", "title": "iOS 9+ Support", "body": "iOS 9 Requires an additional key to previously, where you need to define an array of schemes using the [LSApplicationQueriesSchemes key](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/#//apple_ref/occ/instm/UIApplication/canOpenURL:)." } [/block] # Android On Android, deep linking occurs with the use of Intent Filters. There are 3 main parts to this. First, define your Intent Filter in your app's manifest file, with the `<data>` element filled out. This must be associated with an activity, typically the root. [block:code] { "codes": [ { "code": "<activity android:name=\".MyActivity\">\n\t<intent-filter>\n\t\t<action android:name=\"android.intent.action.VIEW\" />\n\t\t<category android:name=\"android.intent.category.DEFAULT\" />\n\t\t<category android:name=\"android.intent.category.BROWSABLE\" />\n\t\t<data android:scheme=\"myapp\"/>\n\t</intent-filter>\n</activity>", "language": "xml" } ] } [/block] Then, read the `Intent` that was used to start your application in the `onCreate` method of your activity. If your application is already running, the Intent will be sent to the `onNewIntent(Intent)` method of the receiving Activity. [block:code] { "codes": [ { "code": "Intent intent = getIntent();\nif (Intent.ACTION_VIEW.equals(intent.getAction())) {\n\tUri uri = intent.getData();\n\tString valueOne = uri.getQueryParameter(\"keyOne\");\n\tString valueTwo = uri.getQueryParameter(\"keyTwo\");\n}", "language": "java" } ] } [/block] Finally, inside this, parse the URL for any parameters, configure your activity respectively. For implementation details on Intent Filters, have a look in the [Android Developer Library](http://developer.android.com/guide/components/intents-filters.html) on Google's website. # Triggering with Carnival Once implemented by a developer, deep linking URLs can be sent like any other link message. Simply send the link to your audience, and once the user taps on the link, they'll be directed to the correct part of the app. If you want to use deep linking without messages (just using a plain push), then this can be achieved with [Key-Value Payloads](doc:key-value-payloads).