Skip to content

Commit 4bd421e

Browse files
authored
Add HTML Email support to BranchActivityItemProvider. (#619)
* From PR #616 * Add Email HTML support to BranchActivityItemProvider * Updated formatting.
1 parent 1319a20 commit 4bd421e

File tree

5 files changed

+76
-5
lines changed

5 files changed

+76
-5
lines changed

Branch-SDK/Branch-SDK/BranchActivityItemProvider.m

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#import "BranchActivityItemProvider.h"
1010
#import "Branch.h"
11+
#import "BranchConstants.h"
1112
#import "BNCSystemObserver.h"
1213
#import "BNCDeviceInfo.h"
1314

@@ -57,19 +58,67 @@ - (id)item {
5758
NSString *stage = [self stageForChannel:channel];
5859
NSString *campaign = [self campaignForChannel:channel];
5960
NSString *alias = [self aliasForChannel:channel];
60-
61+
6162
// Allow the channel param to be overridden, perhaps they want "fb" instead of "facebook"
6263
if ([self.delegate respondsToSelector:@selector(activityItemOverrideChannelForChannel:)]) {
6364
channel = [self.delegate activityItemOverrideChannelForChannel:channel];
6465
}
6566

66-
// Because Facebook et al immediately scrape URLs, we add an additional parameter to the existing list, telling the backend to ignore the first click
67+
// Because Facebook et al immediately scrape URLs, we add an additional parameter to the
68+
// existing list, telling the backend to ignore the first click
6769
NSArray *scrapers = @[@"Facebook", @"Twitter", @"Slack", @"Apple Notes"];
6870
for (NSString *scraper in scrapers) {
6971
if ([channel isEqualToString:scraper])
70-
return [NSURL URLWithString:[[Branch getInstance] getShortURLWithParams:params andTags:tags andChannel:channel andFeature:feature andStage:stage andCampaign:campaign andAlias:alias ignoreUAString:self.userAgentString forceLinkCreation:YES]];
72+
return [NSURL URLWithString:[[Branch getInstance]
73+
getShortURLWithParams:params
74+
andTags:tags
75+
andChannel:channel
76+
andFeature:feature
77+
andStage:stage
78+
andCampaign:campaign
79+
andAlias:alias
80+
ignoreUAString:self.userAgentString
81+
forceLinkCreation:YES]];
7182
}
72-
return [NSURL URLWithString:[[Branch getInstance] getShortURLWithParams:params andTags:tags andChannel:channel andFeature:feature andStage:stage andCampaign:campaign andAlias:alias ignoreUAString:nil forceLinkCreation:YES]];
83+
84+
// Wrap the link in HTML content
85+
if (self.activityType == UIActivityTypeMail &&
86+
[params objectForKey:BRANCH_LINK_DATA_KEY_EMAIL_HTML_HEADER] &&
87+
[params objectForKey:BRANCH_LINK_DATA_KEY_EMAIL_HTML_FOOTER]) {
88+
NSURL *link = [NSURL URLWithString:[[Branch getInstance]
89+
getShortURLWithParams:params
90+
andTags:tags
91+
andChannel:channel
92+
andFeature:feature
93+
andStage:stage
94+
andCampaign:campaign
95+
andAlias:alias
96+
ignoreUAString:nil
97+
forceLinkCreation:YES]];
98+
NSString *emailLink;
99+
if ([params objectForKey:BRANCH_LINK_DATA_KEY_EMAIL_HTML_LINK_TEXT]) {
100+
emailLink = [NSString stringWithFormat:@"<a href=\"%@\">%@</a>",
101+
link, [params objectForKey:BRANCH_LINK_DATA_KEY_EMAIL_HTML_LINK_TEXT]];
102+
} else {
103+
emailLink = link.absoluteString;
104+
}
105+
106+
return [NSString stringWithFormat:@"<html>%@%@%@</html>",
107+
[params objectForKey:BRANCH_LINK_DATA_KEY_EMAIL_HTML_HEADER],
108+
emailLink,
109+
[params objectForKey:BRANCH_LINK_DATA_KEY_EMAIL_HTML_FOOTER]];
110+
}
111+
112+
return [NSURL URLWithString:[[Branch getInstance]
113+
getShortURLWithParams:params
114+
andTags:tags
115+
andChannel:channel
116+
andFeature:feature
117+
andStage:stage
118+
andCampaign:campaign
119+
andAlias:alias
120+
ignoreUAString:nil
121+
forceLinkCreation:YES]];
73122

74123
}
75124

Branch-SDK/Branch-SDK/BranchConstants.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ extern NSString * const BRANCH_LINK_DATA_KEY_CANONICAL_URL;
104104
extern NSString * const BRANCH_LINK_DATA_KEY_CONTENT_EXPIRATION_DATE;
105105
extern NSString * const BRANCH_LINK_DATA_KEY_CONTENT_TYPE;
106106
extern NSString * const BRANCH_LINK_DATA_KEY_EMAIL_SUBJECT;
107+
extern NSString * const BRANCH_LINK_DATA_KEY_EMAIL_HTML_HEADER;
108+
extern NSString * const BRANCH_LINK_DATA_KEY_EMAIL_HTML_FOOTER;
109+
extern NSString * const BRANCH_LINK_DATA_KEY_EMAIL_HTML_LINK_TEXT;
107110

108111
extern NSString * const BRANCH_SPOTLIGHT_PREFIX;
109112

Branch-SDK/Branch-SDK/BranchConstants.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@
103103
NSString * const BRANCH_LINK_DATA_KEY_CONTENT_EXPIRATION_DATE = @"$exp_date";
104104
NSString * const BRANCH_LINK_DATA_KEY_CONTENT_TYPE = @"$content_type";
105105
NSString * const BRANCH_LINK_DATA_KEY_EMAIL_SUBJECT = @"$email_subject";
106+
NSString * const BRANCH_LINK_DATA_KEY_EMAIL_HTML_HEADER = @"$email_html_header";
107+
NSString * const BRANCH_LINK_DATA_KEY_EMAIL_HTML_FOOTER = @"$email_html_footer";
108+
NSString * const BRANCH_LINK_DATA_KEY_EMAIL_HTML_LINK_TEXT = @"$email_html_link_text";
106109

107110
NSString * const BRANCH_SPOTLIGHT_PREFIX = @"io.branch.link.v1";
108111

ChangeLog.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ Branch iOS SDK Change Log
88
- Added environment parameters to control the test cases without re-compiling.
99
- Standardized test cases.
1010
- All tests pass.
11-
* Updated README.md SDK integration documentation.
11+
* Updated README.md SDK integration documentation to include the new
12+
`[Branch application:openURL:sourceApplication:annotation:annotation]` method.
13+
* Added Email HTML support to BranchActivityItemProvider.
1214

1315
- v0.14.12
1416
* Fixed headers for Swift compatibility AIS-242 (#615).

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,20 @@ The majority of share options only include one string of text, except email, whi
896896
linkProperties.addControlParam("$email_subject", withValue: "Therapists hate him.")
897897
```
898898

899+
You can also optionally add HTML to the email option and customize the link text. If the link text is left out, the url itself is used
900+
901+
```objc
902+
[linkProperties addControlParam:@"$email_html_header" withValue:@"<style>your awesome CSS</style>\nOr Dear Friend,"];
903+
[linkProperties addControlParam:@"$email_html_footer" withValue:@"Thanks!"];
904+
[linkProperties addControlParam:@"$email_html_link_text" withValue:@"Tap here"];
905+
```
906+
907+
```swift
908+
linkProperties.addControlParam("$email_html_header", withValue: "<style>your awesome CSS</style>\nOr Dear Friend,")
909+
linkProperties.addControlParam("$email_html_footer", withValue: "Thanks!")
910+
linkProperties.addControlParam("$email_html_link_text", withValue: "Tap here")
911+
```
912+
899913
#### Returns
900914

901915
None

0 commit comments

Comments
 (0)