Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CTNotificationContent.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
32DFD84F28BCCCBB00E72588 /* CTSingleMediaController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32DFD84128BCCCBB00E72588 /* CTSingleMediaController.swift */; };
32DFD85028BCCCBB00E72588 /* GlobalConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32DFD84428BCCCBB00E72588 /* GlobalConstants.swift */; };
32DFD85128BCCCBB00E72588 /* CTUtility.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32DFD84528BCCCBB00E72588 /* CTUtility.swift */; };
AC10AA0228BCCCBB00E72588 /* CTNotificationContentLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC10AA0128BCCCBB00E72588 /* CTNotificationContentLogger.swift */; };
32E55C0828D87FDD00F1395D /* ct_star_outline.png in Resources */ = {isa = PBXBuildFile; fileRef = 32E55C0628D87FDD00F1395D /* ct_star_outline.png */; };
32E55C0928D87FDD00F1395D /* ct_star_filled.png in Resources */ = {isa = PBXBuildFile; fileRef = 32E55C0728D87FDD00F1395D /* ct_star_filled.png */; };
488F31A72816FFF300AE3AC8 /* ct_next_button.png in Resources */ = {isa = PBXBuildFile; fileRef = 488F31A22816FFF300AE3AC8 /* ct_next_button.png */; };
Expand Down Expand Up @@ -71,6 +72,7 @@
32DFD84128BCCCBB00E72588 /* CTSingleMediaController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CTSingleMediaController.swift; sourceTree = "<group>"; };
32DFD84428BCCCBB00E72588 /* GlobalConstants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GlobalConstants.swift; sourceTree = "<group>"; };
32DFD84528BCCCBB00E72588 /* CTUtility.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CTUtility.swift; sourceTree = "<group>"; };
AC10AA0128BCCCBB00E72588 /* CTNotificationContentLogger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CTNotificationContentLogger.swift; sourceTree = "<group>"; };
32E55C0628D87FDD00F1395D /* ct_star_outline.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = ct_star_outline.png; sourceTree = "<group>"; };
32E55C0728D87FDD00F1395D /* ct_star_filled.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = ct_star_filled.png; sourceTree = "<group>"; };
488F31A22816FFF300AE3AC8 /* ct_next_button.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = ct_next_button.png; sourceTree = "<group>"; };
Expand Down Expand Up @@ -319,6 +321,7 @@
0B0115BD2CAFFD8900985815 /* Extensions.swift */,
32DFD84428BCCCBB00E72588 /* GlobalConstants.swift */,
32DFD84528BCCCBB00E72588 /* CTUtility.swift */,
AC10AA0128BCCCBB00E72588 /* CTNotificationContentLogger.swift */,
);
path = Utility;
sourceTree = "<group>";
Expand Down Expand Up @@ -540,6 +543,7 @@
488F31AF2817000200AE3AC8 /* CTCaptionedImageView.swift in Sources */,
32C575EE28F744E600BF0A3F /* CTRatingsViewController.swift in Sources */,
32DFD85128BCCCBB00E72588 /* CTUtility.swift in Sources */,
AC10AA0228BCCCBB00E72588 /* CTNotificationContentLogger.swift in Sources */,
48D6ACBA2F9248BF00A17777 /* VerticalImageProperties.swift in Sources */,
48D6ACBB2F9248BF00A17777 /* CTVerticalImageController.swift in Sources */,
32DFD84928BCCCBB00E72588 /* TimerTemplateProperties.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

- (NSString *)getDeeplinkUrl; // must override in subclass

- (CTNotificationViewController *)getParentViewController;
/// Returns nil when this controller is not attached to a CTNotificationViewController.
- (nullable CTNotificationViewController *)getParentViewController;

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event;

Expand Down
39 changes: 34 additions & 5 deletions CTNotificationContent/BaseCTNotificationContentViewController.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
#import "BaseCTNotificationContentViewController.h"
#import "CTNotificationViewController.h"

#if __has_include(<CTNotificationContent/CTNotificationContent-Swift.h>)
#import <CTNotificationContent/CTNotificationContent-Swift.h>
#else
#import "CTNotificationContent-Swift.h"
#endif

#define CTContentLogInfo(fmt, ...) \
[CTNotificationContentLogger logInfo:[NSString stringWithFormat:fmt, ##__VA_ARGS__] from:@(__PRETTY_FUNCTION__)]
#define CTContentLogError(fmt, ...) \
[CTNotificationContentLogger logError:[NSString stringWithFormat:fmt, ##__VA_ARGS__] from:@(__PRETTY_FUNCTION__)]

@interface BaseCTNotificationContentViewController ()

@end
Expand All @@ -20,20 +31,38 @@ - (NSString *)getDeeplinkUrl{
}

- (CTNotificationViewController *)getParentViewController {
return (CTNotificationViewController*)self.parentViewController;
UIViewController *parent = self.parentViewController;
if (parent == nil) {
CTContentLogError(@"Nil parentViewController, cannot forward tap, controller=%@",
NSStringFromClass([self class]));
return nil;
}
if (![parent isKindOfClass:[CTNotificationViewController class]]) {
CTContentLogError(@"Expected CTNotificationViewController parent, got %@, cannot forward tap",
NSStringFromClass([parent class]));
return nil;
}
return (CTNotificationViewController *)parent;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

if (@available(iOS 12.0, *)) {
NSString *url = [self getDeeplinkUrl];
if (!url || url.length == 0) {
CTContentLogInfo(@"Tap with no deeplink, performing notification default action");
[[self extensionContext] performNotificationDefaultAction];
return;
}
NSURL *deeplink = [[NSURL alloc] initWithString:url];
if (deeplink == nil) {
CTContentLogError(@"Deeplink parse failed, performing notification default action, url=%@", url);
[[self extensionContext] performNotificationDefaultAction];
}else{
[[self getParentViewController] openUrl:([[NSURL alloc] initWithString:url])];
return;
}
CTContentLogInfo(@"Tap, opening deeplink, url=%@", url);
[[self getParentViewController] openUrl:deeplink];
} else {
// Fallback on earlier versions
CTContentLogError(@"Tap handling requires iOS 12 or later, ignoring");
}
}

Expand Down
Loading