Skip to content

Commit

Permalink
Merge pull request #16 from CleverTap/SDK-1794_ZeroBezelTemplateP
Browse files Browse the repository at this point in the history
origin/SDK-1794_ZeroBezelTemplateP
  • Loading branch information
AishwaryaNanna authored Aug 30, 2022
2 parents 91d9cfb + 71f47e8 commit b43ab5f
Show file tree
Hide file tree
Showing 44 changed files with 969 additions and 467 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Change Log
==========

Version 0.2.1 (30 August, 2022)
-----------------------------------------------
- Supports a new template - Zero Bezel

Version 0.2.0 *(24 June, 2022)*
-----------------------------------------------
- Supports new templates - Basic, Auto carousel, Manual carousel and Timer
Expand Down Expand Up @@ -32,4 +36,4 @@ Version 0.1.1 *(23 July, 2017)*

Version 0.1.0 *(8 March, 2017)*
-------------------------------------------
- Initial release.
- Initial release.
2 changes: 1 addition & 1 deletion CTNotificationContent.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "CTNotificationContent"
s.version = "0.2.0"
s.version = "0.2.1"
s.summary = "A Notification Content Extension class to display custom content interfaces for iOS 10 push notifications"
s.homepage = "https://github.com/CleverTap/CTNotificationContent"
s.license = "MIT"
Expand Down
208 changes: 172 additions & 36 deletions CTNotificationContent.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

88 changes: 39 additions & 49 deletions CTNotificationContent/CTNotificationViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ typedef NS_ENUM(NSInteger, CTNotificationContentType) {
CTNotificationContentTypeAutoCarousel = 3,
CTNotificationContentTypeManualCarousel = 4,
CTNotificationContentTypeTimerTemplate = 5,
CTNotificationContentTypeZeroBezel = 6
};

static NSString * const kTemplateId = @"pt_id";
Expand All @@ -23,12 +24,15 @@ typedef NS_ENUM(NSInteger, CTNotificationContentType) {
static NSString * const kSingleMediaURL = @"ct_mediaUrl";
static NSString * const kJSON = @"pt_json";
static NSString * const kDeeplinkURL = @"wzrk_dl";
static NSString * const kTemplateZeroBezel = @"pt_zero_bezel";

@interface CTNotificationViewController () <UNNotificationContentExtension>

@property(nonatomic, assign) CTNotificationContentType contentType;
@property(nonatomic, strong, readwrite) BaseCTNotificationContentViewController *contentViewController;
@property(nonatomic) NSString *jsonString;
@property(nonatomic) NSDictionary *content;
@property(nonatomic) UNNotification *notification;

@end

Expand All @@ -41,17 +45,19 @@ - (void)viewDidLoad {
}

- (void)didReceiveNotification:(UNNotification *)notification {
NSDictionary *content = notification.request.content.userInfo;
[self updateContentType:content];
_content = notification.request.content.userInfo;
_notification = notification;

[self updateContentType:_content];

switch (self.contentType) {
case CTNotificationContentTypeContentSlider: {
CTContentSliderController *contentController = [[CTContentSliderController alloc] init];
[contentController setData:content[kContentSlider]];
[contentController setData:_content[kContentSlider]];
[contentController setTemplateCaption:notification.request.content.title];
[contentController setTemplateSubcaption:notification.request.content.body];
if (content[kDeeplinkURL] != nil) {
[contentController setDeeplinkURL:content[kDeeplinkURL]];
if (_content[kDeeplinkURL] != nil) {
[contentController setDeeplinkURL:_content[kDeeplinkURL]];
}
[self addChildViewController:contentController];
contentController.view.frame = self.view.frame;
Expand All @@ -63,10 +69,10 @@ - (void)didReceiveNotification:(UNNotification *)notification {
CTSingleMediaController *contentController = [[CTSingleMediaController alloc] init];
[contentController setCaption:notification.request.content.title];
[contentController setSubCaption:notification.request.content.body];
[contentController setMediaType:content[kSingleMediaType]];
[contentController setMediaURL:content[kSingleMediaURL]];
if (content[kDeeplinkURL] != nil) {
[contentController setDeeplinkURL:content[kDeeplinkURL]];
[contentController setMediaType:_content[kSingleMediaType]];
[contentController setMediaURL:_content[kSingleMediaURL]];
if (_content[kDeeplinkURL] != nil) {
[contentController setDeeplinkURL:_content[kDeeplinkURL]];
}
[self addChildViewController:contentController];
contentController.view.frame = self.view.frame;
Expand All @@ -76,61 +82,30 @@ - (void)didReceiveNotification:(UNNotification *)notification {
break;
case CTNotificationContentTypeBasicTemplate: {
CTCarouselController *contentController = [[CTCarouselController alloc] init];
[contentController setData:self.jsonString];
[contentController setTemplateCaption:notification.request.content.title];
[contentController setTemplateSubcaption:notification.request.content.body];
if (content[kDeeplinkURL] != nil) {
[contentController setDeeplinkURL:content[kDeeplinkURL]];
}
[contentController setTemplateType:kTemplateBasic];
[self addChildViewController:contentController];
contentController.view.frame = self.view.frame;
[self.view addSubview:contentController.view];
self.contentViewController = contentController;
[self setupContentController:contentController];
}
break;
case CTNotificationContentTypeAutoCarousel: {
CTCarouselController *contentController = [[CTCarouselController alloc] init];
[contentController setData:self.jsonString];
[contentController setTemplateCaption:notification.request.content.title];
[contentController setTemplateSubcaption:notification.request.content.body];
if (content[kDeeplinkURL] != nil) {
[contentController setDeeplinkURL:content[kDeeplinkURL]];
}
[contentController setTemplateType:kTemplateAutoCarousel];
[self addChildViewController:contentController];
contentController.view.frame = self.view.frame;
[self.view addSubview:contentController.view];
self.contentViewController = contentController;
[self setupContentController:contentController];
}
break;
case CTNotificationContentTypeManualCarousel: {
CTCarouselController *contentController = [[CTCarouselController alloc] init];
[contentController setData:self.jsonString];
[contentController setTemplateCaption:notification.request.content.title];
[contentController setTemplateSubcaption:notification.request.content.body];
if (content[kDeeplinkURL] != nil) {
[contentController setDeeplinkURL:content[kDeeplinkURL]];
}
[contentController setTemplateType:kTemplateManualCarousel];
[self addChildViewController:contentController];
contentController.view.frame = self.view.frame;
[self.view addSubview:contentController.view];
self.contentViewController = contentController;
[self setupContentController:contentController];
}
break;
case CTNotificationContentTypeTimerTemplate: {
CTTimerTemplateController *contentController = [[CTTimerTemplateController alloc] init];
[contentController setData:self.jsonString];
[contentController setTemplateCaption:notification.request.content.title];
[contentController setTemplateSubcaption:notification.request.content.body];
if (content[kDeeplinkURL] != nil) {
[contentController setDeeplinkURL:content[kDeeplinkURL]];
}
[self addChildViewController:contentController];
contentController.view.frame = self.view.frame;
[self.view addSubview:contentController.view];
self.contentViewController = contentController;
[self setupContentController:contentController];
}
break;
case CTNotificationContentTypeZeroBezel: {
CTZeroBezelController *contentController = [[CTZeroBezelController alloc] init];
[self setupContentController:contentController];
}
break;

Expand All @@ -142,6 +117,19 @@ - (void)didReceiveNotification:(UNNotification *)notification {
self.preferredContentSize = self.contentViewController.preferredContentSize;
}

- (void)setupContentController:(id)contentController{
[contentController setData:self.jsonString];
[contentController setTemplateCaption:_notification.request.content.title];
[contentController setTemplateSubcaption:_notification.request.content.body];
if (self.content[kDeeplinkURL] != nil) {
[contentController setDeeplinkURL:self.content[kDeeplinkURL]];
}
[self addChildViewController:contentController];
[contentController view].frame = self.view.frame;
[self.view addSubview:[contentController view]];
self.contentViewController = contentController;
}

- (void)updateContentType:(NSDictionary *)content {
if (content[kContentSlider] != nil) {
self.contentType = CTNotificationContentTypeContentSlider;
Expand All @@ -161,6 +149,8 @@ - (void)updateContentType:(NSDictionary *)content {
self.contentType = CTNotificationContentTypeManualCarousel;
} else if ([content[kTemplateId] isEqualToString:kTemplateTimer]) {
self.contentType = CTNotificationContentTypeTimerTemplate;
}else if ([content[kTemplateId] isEqualToString:kTemplateZeroBezel]) {
self.contentType = CTNotificationContentTypeZeroBezel;
} else {
// Invalid pt_id value fallback to basic.
self.contentType = CTNotificationContentTypeBasicTemplate;
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
import UIKit
import UserNotificationsUI

struct CarouselProperties: Decodable {
let pt_title: String?
let pt_msg: String?
let pt_msg_summary: String?
let pt_dl1: String?
let pt_big_img: String?
let pt_img1: String?
let pt_img2: String?
let pt_img3: String?
let pt_bg: String?
let pt_title_clr: String?
let pt_msg_clr: String?
}

@objc public class CTCarouselController: BaseCTNotificationContentViewController {
var contentView: UIView = UIView(frame: .zero)
var pageControl: UIPageControl = UIPageControl(frame: .zero)
Expand Down Expand Up @@ -42,21 +28,10 @@ struct CarouselProperties: Decodable {
contentView = UIView(frame: view.frame)
view.addSubview(contentView)

loadContentData()
jsonContent = CTUtiltiy.loadContentData(data: data)
createView()
}

func loadContentData() {
if let configData = data.data(using: .utf8) {
do {
jsonContent = try JSONDecoder().decode(CarouselProperties.self, from: configData)
} catch let error {
print("Failed to load: \(error.localizedDescription)")
jsonContent = nil
}
}
}

func createView() {
guard let jsonContent = jsonContent else {
// Show default alert view and update constraints when json data is not available.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// CarouselProperties.swift
// CleverTap-iOS-SDK
//
// Created by Aishwarya Nanna on 26/08/22.
//

import Foundation

struct CarouselProperties: Decodable {
let pt_title: String?
let pt_msg: String?
let pt_msg_summary: String?
let pt_dl1: String?
let pt_big_img: String?
let pt_img1: String?
let pt_img2: String?
let pt_img3: String?
let pt_bg: String?
let pt_title_clr: String?
let pt_msg_clr: String?
}
Loading

0 comments on commit b43ab5f

Please sign in to comment.