Skip to content
Merged
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
7 changes: 7 additions & 0 deletions doc/CustomCodeTemplates.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ Call `[CleverTapPluginCustomTemplates registerCustomTemplates]` in your `AppDele
}
```

If your app uses the `UIScene` lifecycle, also notify the plugin of the cold-launch push payload from your SceneDelegate so `getInitialUrl` keeps working (see [Integrate-iOS.md](Integrate-iOS.md#handling-deep-links-under-the-uiscene-lifecycle)):
```objc
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
[[CleverTapPlugin sharedInstance] sceneWillConnectWithOptions:connectionOptions];
}
```

## Syncing in-app templates to the dashboard

For the templates to be usable in campaigns they must be synced with the dashboard. When all templates and functions are defined and registered in the SDK, they can be synced by calling `CleverTap.syncCustomTemplates()` or `CleverTap.syncCustomTemplatesInProd()` in your Flutter application. The syncing can only be done in debug builds and with an SDK user marked as a "test user". We recommend only calling this function while developing the templates and deleting the invocation in release builds.
Expand Down
22 changes: 21 additions & 1 deletion doc/Integrate-iOS.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,27 @@ After installation, you will need to integrate CleverTap SDK into your app.
CleverTap.autoIntegrate() // integrate CleverTap SDK using the autoIntegrate option
CleverTapPlugin.sharedInstance()?.applicationDidLaunch(options: launchOptions)
```


### Handling deep links under the UIScene lifecycle

If your app uses the `UIScene` lifecycle (a `SceneDelegate` with a `UIApplicationSceneManifest` in `Info.plist`), the cold-launch push payload is delivered to `scene(_:willConnectTo:options:)` rather than `didFinishLaunchingWithOptions:`. In that case `launchOptions` is `nil`, so you must ALSO notify the plugin from your SceneDelegate for `getInitialUrl` to return the deep link on a cold launch.

###### Objective-C
```objc
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
[[CleverTapPlugin sharedInstance] sceneWillConnectWithOptions:connectionOptions];
}
```

###### Swift
```swift
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
CleverTapPlugin.sharedInstance()?.sceneWillConnect(withOptions: connectionOptions)
}
```

> Apps that do NOT use the `UIScene` lifecycle need no changes - keep calling `applicationDidLaunchWithOptions:` from `didFinishLaunchingWithOptions:` as shown above.

### Set up and register for push notifications

1. [Set up push notifications for your app](https://developer.apple.com/documentation/usernotifications/registering_your_app_with_apns).
Expand Down
1 change: 1 addition & 0 deletions ios/Classes/CleverTapPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ static NSString *const kCleverTapCustomTemplateClose = @"c
+ (instancetype)sharedInstance;

- (void)applicationDidLaunchWithOptions:(NSDictionary *)options;
- (void)sceneWillConnectWithOptions:(UISceneConnectionOptions *)connectionOptions API_AVAILABLE(ios(13.0));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we have another PR which moves these files to other folder, there will be merge conflict. @akashvercetti @reshab-code check order of PR merge for these 2 PRs or create a feature branch to be safe side before merging it to develop directly, as version bump PR also have one api changes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes a feature base branch will be needed for 4 PRs:
@reshab-code make a new feature branch with the word "4.2.0" in it and change the base branch of all 4 PRs.
I think your SPM PR should be merged last cuz u moved some files in another folder.

#363
#356
#364
#369

- (void)postNotificationWithName:(NSString *)name andBody:(NSDictionary *)body;

@property NSString *launchDeepLink;
Expand Down
31 changes: 29 additions & 2 deletions ios/Classes/CleverTapPlugin.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

#import <UserNotifications/UserNotifications.h>
#import "CleverTap.h"
#import "CleverTapPlugin.h"
#import "CleverTap+Inbox.h"
Expand Down Expand Up @@ -79,6 +80,20 @@ - (void)applicationDidLaunchWithOptions:(NSDictionary *)options {
}
}

- (void)sceneWillConnectWithOptions:(UISceneConnectionOptions *)connectionOptions API_AVAILABLE(ios(13.0)) {

if (@available(iOS 13.0, *)) {
UNNotificationResponse *response = connectionOptions.notificationResponse;
if (response) {
NSDictionary *userInfo = response.notification.request.content.userInfo;
if (userInfo && userInfo[@"wzrk_dl"]) {
self.launchDeepLink = userInfo[@"wzrk_dl"];
NSLog(@"CleverTapFlutter: setting launch deeplink (scene): %@", self.launchDeepLink);
}
}
}
}

- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {

if ([@"getPlatformVersion" isEqualToString:call.method])
Expand Down Expand Up @@ -780,16 +795,28 @@ - (void)fetchInboxWithCallback:(FlutterMethodCall *)call withResult:(FlutterResu
}];
}

- (UIWindow *)ct_keyWindow {

if (@available(iOS 11.0, *)) {
for (UIWindow *window in [UIApplication sharedApplication].windows) {
if (window.isKeyWindow) {
return window;
}
}
}
return [[UIApplication sharedApplication] keyWindow];
}

- (void)showInbox:(FlutterMethodCall *)call withResult:(FlutterResult)result {

NSDictionary *styleConfig = call.arguments[@"styleConfig"];
if ([styleConfig isKindOfClass:[NSNull class]]) {
styleConfig = nil;
}
CleverTapInboxViewController *inboxController = [[CleverTap sharedInstance] newInboxViewControllerWithConfig:[self _dictToInboxStyleConfig:styleConfig ? styleConfig : nil] andDelegate:(id <CleverTapInboxViewControllerDelegate>)self];
if (inboxController) {
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:inboxController];
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
UIWindow *keyWindow = [self ct_keyWindow];
UIViewController *mainViewController = keyWindow.rootViewController;
[mainViewController presentViewController:navigationController animated:YES completion:nil];
}
Expand Down