Skip to content

Commit

Permalink
Merge pull request #16 from WebEngage/push_revamp
Browse files Browse the repository at this point in the history
Rich text support added
  • Loading branch information
BhaveshWebEngage authored Mar 10, 2022
2 parents 292fd77 + c1c130c commit 29d19de
Show file tree
Hide file tree
Showing 20 changed files with 1,186 additions and 161 deletions.
60 changes: 34 additions & 26 deletions Extension App/ContentExtension/Info.plist
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>ContentExtension</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSExtension</key>
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>ContentExtension</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
Expand All @@ -30,19 +30,27 @@
<array>
<string>WEG_CAROUSEL_V1</string>
<string>WEG_RATING_V1</string>
<string>WEG_RICH_V1</string>
<string>WEG_RICH_V2</string>
<string>WEG_RICH_V3</string>
<string>WEG_RICH_V4</string>
<string>WEG_RICH_V5</string>
<string>WEG_RICH_V6</string>
<string>WEG_RICH_V7</string>
<string>WEG_RICH_V8</string>
</array>
<key>UNNotificationExtensionInitialContentSizeRatio</key>
<real>1</real>
<integer>1</integer>
</dict>
<key>NSExtensionMainStoryboard</key>
<string>MainInterface</string>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.usernotifications.content-extension</string>
</dict>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
</dict>
</dict>
</plist>
16 changes: 16 additions & 0 deletions Extension App/WEGExtensionApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@
56A49FB8EB9E003121E4C723 /* Pods-WEGExtensionApp.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WEGExtensionApp.debug.xcconfig"; path = "Pods/Target Support Files/Pods-WEGExtensionApp/Pods-WEGExtensionApp.debug.xcconfig"; sourceTree = "<group>"; };
8167C6E259A361F9B2183151 /* libPods-WEGExtensionApp.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-WEGExtensionApp.a"; sourceTree = BUILT_PRODUCTS_DIR; };
8288374F4CC9F6A69DC1929F /* Pods-ContentExtension.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ContentExtension.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ContentExtension/Pods-ContentExtension.debug.xcconfig"; sourceTree = "<group>"; };
A67089DF27A019E200DF27AC /* UIColor+DarkMode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIColor+DarkMode.h"; sourceTree = "<group>"; };
A67089E027A019EF00DF27AC /* UIColor+DarkMode.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIColor+DarkMode.m"; sourceTree = "<group>"; };
A693721927C0134F00045C60 /* WEXTextPushNotificationViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WEXTextPushNotificationViewController.h; sourceTree = "<group>"; };
A693721A27C0135D00045C60 /* WEXTextPushNotificationViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = WEXTextPushNotificationViewController.m; sourceTree = "<group>"; };
A6DDEE99279A7A8D007FADE1 /* NSMutableAttributedString+Additions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSMutableAttributedString+Additions.h"; sourceTree = "<group>"; };
A6DDEE9A279A7B22007FADE1 /* NSMutableAttributedString+Additions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSMutableAttributedString+Additions.m"; sourceTree = "<group>"; };
A6F5D066278D6EA1005A96AA /* WEXBannerPushNotificationViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WEXBannerPushNotificationViewController.h; sourceTree = "<group>"; };
A6F5D067278D6EAE005A96AA /* WEXBannerPushNotificationViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = WEXBannerPushNotificationViewController.m; sourceTree = "<group>"; };
B554331A99838E3647290F86 /* Pods-ServiceExtension.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ServiceExtension.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ServiceExtension/Pods-ServiceExtension.debug.xcconfig"; sourceTree = "<group>"; };
BF5C12043F19FA4C36D82355 /* Pods-WEGExtensionApp.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WEGExtensionApp.release.xcconfig"; path = "Pods/Target Support Files/Pods-WEGExtensionApp/Pods-WEGExtensionApp.release.xcconfig"; sourceTree = "<group>"; };
CF34E9CCD03C284D4C70479B /* Pods-ContentExtension.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ContentExtension.release.xcconfig"; path = "Pods/Target Support Files/Pods-ContentExtension/Pods-ContentExtension.release.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -265,6 +273,14 @@
EC9A3DBA21B6B15300C63B7D /* WEXRichPushNotificationViewController.h */,
EC9A3DB721B6B15300C63B7D /* WEXRichPushNotificationViewController.m */,
EC9A3DB521B6B15300C63B7D /* WEXRichPushNotificationViewController+Private.h */,
A6F5D066278D6EA1005A96AA /* WEXBannerPushNotificationViewController.h */,
A6F5D067278D6EAE005A96AA /* WEXBannerPushNotificationViewController.m */,
A6DDEE99279A7A8D007FADE1 /* NSMutableAttributedString+Additions.h */,
A6DDEE9A279A7B22007FADE1 /* NSMutableAttributedString+Additions.m */,
A67089DF27A019E200DF27AC /* UIColor+DarkMode.h */,
A67089E027A019EF00DF27AC /* UIColor+DarkMode.m */,
A693721927C0134F00045C60 /* WEXTextPushNotificationViewController.h */,
A693721A27C0135D00045C60 /* WEXTextPushNotificationViewController.m */,
);
path = ContentExtension;
sourceTree = "<group>";
Expand Down
7 changes: 2 additions & 5 deletions Extension App/WEGExtensionApp/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,16 @@

import UIKit
import WebEngage
import UserNotifications

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

WebEngage.sharedInstance()?.application(application, didFinishLaunchingWithOptions: launchOptions, autoRegister: true)

NSLog("Extension Demo app launched " + #function)

WebEngage.sharedInstance().user.login("ExtensionQWE1")
return true
}
}

2 changes: 1 addition & 1 deletion Extension App/WEGExtensionApp/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<key>WEGEnableLocationAuthorizationRequest</key>
<string>IN_USE</string>
<key>WEGLicenseCode</key>
<string>311c5607</string>
<string>d3a4a436</string>
<key>WEGLogLevel</key>
<string>VERBOSE</string>
<key>NSAppTransportSecurity</key>
Expand Down
4 changes: 2 additions & 2 deletions WebEngageAppEx.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |spec|

spec.name = 'WebEngageAppEx'
spec.version = '0.12.0'
spec.version = '1.0.0'

spec.summary = 'App Extension Target SDK for WebEngage for Rich Push Notifications support.'

Expand All @@ -10,7 +10,7 @@ Pod::Spec.new do |spec|
DESC

spec.license = 'MIT'
spec.author = 'Saumitra Bhave', 'Uzma Sayyed', 'Unmesh Rathod'
spec.author = 'Saumitra Bhave', 'Uzma Sayyed', 'Unmesh Rathod', 'Bhavesh Sarwar'
spec.homepage = 'https://webengage.com'
spec.social_media_url = 'http://twitter.com/webengage'
spec.documentation_url = 'https://docs.webengage.com/docs/ios-getting-started'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// NSMutableAttributedString+Additions.h
// WebEngage
//
// Copyright (c) 2017 Webklipper Technologies Pvt Ltd. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface NSMutableAttributedString (Additions)

- (void)updateDefaultTextColor;

- (void)setFontFaceWithFont:(UIFont *)font;

- (void)trimWhiteSpace;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//
// NSMutableAttributedString+Additions.m
// WebEngage
//
// Copyright (c) 2017 Webklipper Technologies Pvt Ltd. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "NSMutableAttributedString+Additions.h"
#import "UIColor+DarkMode.h"

@implementation NSMutableAttributedString (Additions)

- (void)updateDefaultTextColor {
if (@available(iOS 13.0, *)) {
[self beginEditing];
[self enumerateAttribute:NSForegroundColorAttributeName
inRange:NSMakeRange(0, self.length)
options:0
usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {

UIColor *color = (UIColor *)value;
UIColor *labelColor = [UIColor WEXLabelColor];
NSString *colorHex = [self hexStringFromColor:color];

if ([colorHex isEqualToString:@"000000"]) {
[self removeAttribute:NSForegroundColorAttributeName range:range];
[self addAttribute:NSForegroundColorAttributeName value:labelColor range:range];
}
}];
[self endEditing];
}
}

- (NSString *)hexStringFromColor:(UIColor *)color {
const CGFloat *components = CGColorGetComponents(color.CGColor);

CGFloat r = components[0];
CGFloat g = components[1];
CGFloat b = components[2];

return [NSString stringWithFormat:@"%02lX%02lX%02lX",
lroundf(r * 255),
lroundf(g * 255),
lroundf(b * 255)];
}

- (void)setFontFaceWithFont:(UIFont *)font {
[self beginEditing];
[self enumerateAttribute:NSFontAttributeName
inRange:NSMakeRange(0, self.length)
options:0
usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {

UIFont *oldFont = (UIFont *)value;
UIFontDescriptor *newFontDescriptor = [[oldFont.fontDescriptor fontDescriptorWithFamily:font.familyName] fontDescriptorWithSymbolicTraits:oldFont.fontDescriptor.symbolicTraits];
UIFont *newFont = [UIFont fontWithDescriptor:newFontDescriptor size:font.pointSize];

if (newFont) {
[self removeAttribute:NSFontAttributeName range:range];
[self addAttribute:NSFontAttributeName value:newFont range:range];
}
}];
[self endEditing];
}

- (void)trimWhiteSpace {
NSCharacterSet *legalChars = [[NSCharacterSet whitespaceAndNewlineCharacterSet] invertedSet];
NSRange startRange = [self.string rangeOfCharacterFromSet: legalChars];
NSRange endRange = [self.string rangeOfCharacterFromSet: legalChars options:NSBackwardsSearch];
if (startRange.location == NSNotFound || endRange.location == NSNotFound) {
// there are no legal characters in self --- it is ALL whitespace, and so we 'trim' everything leaving an empty string
[self setAttributedString:[NSAttributedString new]];
}
else {
NSUInteger startLocation = NSMaxRange(startRange), endLocation = endRange.location;
NSRange range = NSMakeRange(startLocation - 1, endLocation - startLocation + 2);
[self setAttributedString:[self attributedSubstringFromRange:range]];
}
}

@end
22 changes: 22 additions & 0 deletions WebEngageAppEx/Classes/ContentExtension/UIColor+DarkMode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// UIColor+DarkMode.h
// WebEngage
//
// Copyright (c) 2017 Webklipper Technologies Pvt Ltd. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface UIColor (DarkMode)

+ (UIColor *)WEXWhiteColor;

+ (UIColor *)WEXGreyColor;

+ (UIColor *)WEXLabelColor;

+ (UIColor *)WEXLightTextColor;

+ (UIColor *)colorFromHexString:(NSString *)hexString defaultColor:(UIColor *)defaultColor;

@end
63 changes: 63 additions & 0 deletions WebEngageAppEx/Classes/ContentExtension/UIColor+DarkMode.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//
// UIColor+DarkMode.m
// WebEngage
//
// Copyright (c) 2017 Webklipper Technologies Pvt Ltd. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "UIColor+DarkMode.h"

@implementation UIColor (DarkMode)

+ (UIColor *)WEXWhiteColor {
if (@available(iOS 13.0, *)) {
return UIColor.systemBackgroundColor;
} else {
return UIColor.whiteColor;
}
}

+ (UIColor *)WEXGreyColor {
if (@available(iOS 13.0, *)) {
return UIColor.systemGrayColor;
} else {
return UIColor.lightGrayColor;
}
}

+ (UIColor *)WEXLabelColor {
if (@available(iOS 13.0, *)) {
return UIColor.labelColor;
} else {
return UIColor.blackColor;
}
}

+ (UIColor *)WEXLightTextColor {
if (@available(iOS 13.0, *)) {
return UIColor.systemGray4Color;
} else {
return UIColor.lightTextColor;
}
}

+ (UIColor *)colorFromHexString:(NSString *)hexString defaultColor:(UIColor *)defaultColor {
if (hexString == (id)[NSNull null] || hexString.length == 0) {
return defaultColor;
}

unsigned rgbValue = 0;
NSScanner *scanner = [NSScanner scannerWithString:hexString];

if ([hexString hasPrefix:@"#"]) {
[scanner setScanLocation:1]; // bypass '#' character
} else {
[scanner setScanLocation:0];
}

[scanner scanHexInt:&rgbValue];
return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:1.0];
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// WEXBannerPushNotificationViewController.h
// WebEngage
//
// Copyright (c) 2022 Webklipper Technologies Pvt Ltd. All rights reserved.
//

#import <UIKit/UIKit.h>

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000
#import <UserNotifications/UserNotifications.h>
#import <UserNotificationsUI/UserNotificationsUI.h>
#import "WEXRichPushNotificationViewController+Private.h"
#import "WEXRichPushLayout.h"
#endif

@interface WEXBannerPushNotificationViewController
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000
: WEXRichPushLayout
#else
: NSObject
#endif

@end
Loading

0 comments on commit 29d19de

Please sign in to comment.