Skip to content

Commit

Permalink
Update example app
Browse files Browse the repository at this point in the history
  • Loading branch information
soczowinski committed Jun 30, 2023
1 parent dd7ad6b commit ab32785
Show file tree
Hide file tree
Showing 16 changed files with 1,100 additions and 37 deletions.
18 changes: 18 additions & 0 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@ target 'SampleAppFlutter' do
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end

target 'SyneriseNotificationServiceExtension' do

pod 'SyneriseSDK', '4.13.1'

end

target 'SyneriseSingleMediaNotificationContentExtension' do

pod 'SyneriseSDK', '4.13.1'

end

target 'SyneriseCarouselNotificationContentExtension' do

pod 'SyneriseSDK', '4.13.1'

end

post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
Expand Down
37 changes: 19 additions & 18 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ PODS:
- FirebaseCoreInternal (~> 10.0)
- GoogleUtilities/Environment (~> 7.8)
- GoogleUtilities/Logger (~> 7.8)
- FirebaseCoreInternal (10.6.0):
- FirebaseCoreInternal (10.11.0):
- "GoogleUtilities/NSData+zlib (~> 7.8)"
- FirebaseInstallations (10.6.0):
- FirebaseInstallations (10.11.0):
- FirebaseCore (~> 10.0)
- GoogleUtilities/Environment (~> 7.8)
- GoogleUtilities/UserDefaults (~> 7.8)
Expand Down Expand Up @@ -79,36 +79,36 @@ PODS:
- GoogleUtilities/Network (~> 7.8)
- "GoogleUtilities/NSData+zlib (~> 7.8)"
- nanopb (< 2.30910.0, >= 2.30908.0)
- GoogleDataTransport (9.2.1):
- GoogleDataTransport (9.2.3):
- GoogleUtilities/Environment (~> 7.7)
- nanopb (< 2.30910.0, >= 2.30908.0)
- PromisesObjC (< 3.0, >= 1.2)
- GoogleUtilities/AppDelegateSwizzler (7.11.0):
- GoogleUtilities/AppDelegateSwizzler (7.11.1):
- GoogleUtilities/Environment
- GoogleUtilities/Logger
- GoogleUtilities/Network
- GoogleUtilities/Environment (7.11.0):
- GoogleUtilities/Environment (7.11.1):
- PromisesObjC (< 3.0, >= 1.2)
- GoogleUtilities/Logger (7.11.0):
- GoogleUtilities/Logger (7.11.1):
- GoogleUtilities/Environment
- GoogleUtilities/MethodSwizzler (7.11.0):
- GoogleUtilities/MethodSwizzler (7.11.1):
- GoogleUtilities/Logger
- GoogleUtilities/Network (7.11.0):
- GoogleUtilities/Network (7.11.1):
- GoogleUtilities/Logger
- "GoogleUtilities/NSData+zlib"
- GoogleUtilities/Reachability
- "GoogleUtilities/NSData+zlib (7.11.0)"
- GoogleUtilities/Reachability (7.11.0):
- "GoogleUtilities/NSData+zlib (7.11.1)"
- GoogleUtilities/Reachability (7.11.1):
- GoogleUtilities/Logger
- GoogleUtilities/UserDefaults (7.11.0):
- GoogleUtilities/UserDefaults (7.11.1):
- GoogleUtilities/Logger
- nanopb (2.30909.0):
- nanopb/decode (= 2.30909.0)
- nanopb/encode (= 2.30909.0)
- nanopb/decode (2.30909.0)
- nanopb/encode (2.30909.0)
- PromisesObjC (2.2.0)
- synerise_flutter_sdk (0.6.0):
- synerise_flutter_sdk (0.6.2):
- Flutter
- SyneriseSDK (= 4.13.1)
- SyneriseSDK (4.13.1)
Expand All @@ -119,6 +119,7 @@ DEPENDENCIES:
- firebase_messaging (from `.symlinks/plugins/firebase_messaging/ios`)
- Flutter (from `Flutter`)
- synerise_flutter_sdk (from `.symlinks/plugins/synerise_flutter_sdk/ios`)
- SyneriseSDK (= 4.13.1)

SPEC REPOS:
trunk:
Expand Down Expand Up @@ -154,18 +155,18 @@ SPEC CHECKSUMS:
firebase_messaging: 8ac28baba96e69a58ad26b4bb5f9ee67c3e5efe2
FirebaseAnalytics: 036232b6a1e2918e5f67572417be1173576245f3
FirebaseCore: 988754646ab3bd4bdcb740f1bfe26b9f6c0d5f2a
FirebaseCoreInternal: c7cd505e2136811096b225ac388d6254a2622362
FirebaseInstallations: 13dde135fa0524e15bddb133ccc8465c53a1b3f3
FirebaseCoreInternal: 9e46c82a14a3b3a25be4e1e151ce6d21536b89c0
FirebaseInstallations: 2a2c6859354cbec0a228a863d4daf6de7c74ced4
FirebaseMessaging: e345b219fd15d325f0cf2fef28cb8ce00d851b3f
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
GoogleAppMeasurement: c7d6fff39bf2d829587d74088d582e32d75133c3
GoogleDataTransport: ea169759df570f4e37bdee1623ec32a7e64e67c4
GoogleUtilities: c2bdc4cf2ce786c4d2e6b3bcfd599a25ca78f06f
GoogleDataTransport: f0308f5905a745f94fb91fea9c6cbaf3831cb1bd
GoogleUtilities: 9aa0ad5a7bc171f8bae016300bfcfa3fb8425749
nanopb: b552cce312b6c8484180ef47159bc0f65a1f0431
PromisesObjC: 09985d6d70fbe7878040aa746d78236e6946d2ef
synerise_flutter_sdk: 7b390468eaa1370d1feaa791e04214e1266b0d5b
synerise_flutter_sdk: 3bf373dedd3c8029df803e684d030e102d8c242d
SyneriseSDK: 811c9cad83d986a1ad0bac1826c6c0fb1fc9fe35

PODFILE CHECKSUM: b602315bb3a87d075487d5bf49aca41dbe87716b
PODFILE CHECKSUM: d4b311433acbfaca5931fa80e48619297945167e

COCOAPODS: 1.11.3
810 changes: 798 additions & 12 deletions example/ios/Runner.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

24 changes: 19 additions & 5 deletions example/ios/Runner/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
#import "AppDelegate.h"
#import "GeneratedPluginRegistrant.h"
#import <SyneriseSDK/SyneriseSDK.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GeneratedPluginRegistrant registerWithRegistry:self];
// Override point for customization after application launch.
return [super application:application didFinishLaunchingWithOptions:launchOptions];
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UNNotificationCategory *singleMediaCategory = [UNNotificationCategory categoryWithIdentifier:SNRSingleMediaContentExtensionViewControllerCategoryIdentifier actions:@[] intentIdentifiers:@[] options:0];

UNNotificationAction *carouselPreviousAction = [UNNotificationAction actionWithIdentifier:SNRCarouselContentExtensionViewControllerPreviousItemIdentifier title:@"Previous" options:0];

UNNotificationAction *carouselGoAction = [UNNotificationAction actionWithIdentifier:SNRCarouselContentExtensionViewControllerChooseItemIdentifier title:@"Go" options:0];

UNNotificationAction *carouselNextAction = [UNNotificationAction actionWithIdentifier:SNRCarouselContentExtensionViewControllerNextItemIdentifier title:@"Next" options:0];

UNNotificationCategory *carouselCategory = [UNNotificationCategory categoryWithIdentifier:SNRCarouselContentExtensionViewControllerCategoryIdentifier actions:@[carouselPreviousAction, carouselGoAction, carouselNextAction] intentIdentifiers:@[] options:0];

[[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:[NSSet setWithObjects:singleMediaCategory, carouselCategory, nil]];


[GeneratedPluginRegistrant registerWithRegistry:self];
// Override point for customization after application launch.

return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

@end
8 changes: 8 additions & 0 deletions example/ios/SampleAppFlutter.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,13 @@
<dict>
<key>aps-environment</key>
<string>development</string>
<key>com.apple.security.application-groups</key>
<array>
<string>group.com.synerise.sdk.sample-flutter</string>
</array>
<key>keychain-access-groups</key>
<array>
<string>$(AppIdentifierPrefix)FlutterKeychainGroup</string>
</array>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>UNNotificationExtensionCategory</key>
<array>
<string>synerise.notifications.category.carousel</string>
</array>
<key>UNNotificationExtensionDefaultContentHidden</key>
<true/>
<key>UNNotificationExtensionInitialContentSizeRatio</key>
<real>1</real>
</dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.usernotifications.content-extension</string>
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).NotificationViewController</string>
</dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// NotificationViewController.swift
// SyneriseCarouselNotificationContentExtension
//
// Created by Krzysztof Kurzawa on 29/06/2023.
//

import UIKit
import UserNotifications
import UserNotificationsUI
import SyneriseSDK

class NotificationViewController: CarouselContentExtensionViewController, UNNotificationContentExtension {

func didReceive(_ notification: UNNotification) {
Synerise.settings.sdk.appGroupIdentifier = "group.com.synerise.sdk.flutter"
Synerise.settings.sdk.keychainGroupIdentifier = "34N2Z22TKH.FlutterKeychainGroup"

setSyneriseNotification(notification)
}

func didReceive(_ response: UNNotificationResponse, completionHandler completion: @escaping (UNNotificationContentExtensionResponseOption) -> Void) {
setSyneriseNotificationResponse(response, completionHandler: completion)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?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>com.apple.security.application-groups</key>
<array>
<string>group.com.synerise.sdk.sample-flutter</string>
</array>
<key>keychain-access-groups</key>
<array>
<string>$(AppIdentifierPrefix)FlutterKeychainGroup</string>
</array>
</dict>
</plist>
13 changes: 13 additions & 0 deletions example/ios/SyneriseNotificationServiceExtension/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?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>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.usernotifications.service</string>
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).NotificationService</string>
</dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//
// NotificationService.swift
// SyneriseNotificationServiceExtension
//
// Created by Krzysztof Kurzawa on 29/06/2023.
//

import UserNotifications
import SyneriseSDK

class NotificationService: UNNotificationServiceExtension, NotificationServiceExtensionDelegate, NotificationDelegate {

var contentHandler: ((UNNotificationContent) -> Void)?
var receivedRequest: UNNotificationRequest?
var bestAttemptContent: UNMutableNotificationContent?

override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.receivedRequest = request
self.contentHandler = contentHandler
self.bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)

if let bestAttemptContent = self.bestAttemptContent {
Synerise.settings.sdk.appGroupIdentifier = "group.com.synerise.sdk.flutter"
Synerise.settings.sdk.keychainGroupIdentifier = "34N2Z22TKH.FlutterKeychainGroup"

NotificationServiceExtension.setDelegate(self)
NotificationServiceExtension.setNotificationDelegate(self)

#if DEBUG
NotificationServiceExtension.setDebugModeEnabled(true)
#endif

// DEBUG ONLY !!!
// Uncomment the 1 line below to cause service extension expiration and check how `serviceExtensionTimeWillExpire` method works.
// Thread.sleep(forTimeInterval: 25)

NotificationServiceExtension.setDecryptionFallbackNotificationTitleAndBody(title: "(Encrypted)", body: "(Encrypted)")
NotificationServiceExtension.didReceiveNotificationExtensionRequest(request, withMutableNotificationContent: bestAttemptContent)

// DEBUG ONLY !!!
// Uncomment the 1 line below and comment out the one above to ensure this extension is executing.
// Remember, this extension only runs when mutable-content is set true in Synerise campaign options.
// bestAttemptContent.body = "[Modified]".appending(bestAttemptContent.body);
contentHandler(bestAttemptContent)
}
}

override func serviceExtensionTimeWillExpire() {
// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
if let contentHandler = self.contentHandler, let receivedRequest = self.receivedRequest, let bestAttemptContent = self.bestAttemptContent {
NotificationServiceExtension.serviceExtensionTimeWillExpireRequest(receivedRequest, withMutableNotificationContent: bestAttemptContent)
bestAttemptContent.title = "Fallback title"
bestAttemptContent.body = "Fallback body"
contentHandler(bestAttemptContent)
}
}

func notificationServiceExtensionDidFailProcessingWithError(_ error: Error) {
#if DEBUG
self.bestAttemptContent?.title = error.localizedDescription
#endif
}

func notificationServiceExtensionDidFailDecryptionWithError(_ error: Error) {
#if DEBUG
self.bestAttemptContent?.title = error.localizedDescription
#endif
}

func snr_notificationDidReceive(notificationInfo: NotificationInfo) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?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>com.apple.security.application-groups</key>
<array>
<string>group.com.synerise.sdk.sample-flutter</string>
</array>
<key>keychain-access-groups</key>
<array>
<string>$(AppIdentifierPrefix)FlutterKeychainGroup</string>
</array>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>UNNotificationExtensionCategory</key>
<array>
<string>synerise.notifications.category.single-media</string>
</array>
<key>UNNotificationExtensionDefaultContentHidden</key>
<true/>
<key>UNNotificationExtensionInitialContentSizeRatio</key>
<real>1</real>
</dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.usernotifications.content-extension</string>
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).NotificationViewController</string>
</dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// NotificationViewController.swift
// SyneriseSingleMediaNotificationContentExtension
//
// Created by Krzysztof Kurzawa on 29/06/2023.
//

import UIKit
import UserNotifications
import UserNotificationsUI
import SyneriseSDK

class NotificationViewController: SingleMediaContentExtensionViewController, UNNotificationContentExtension {

override func viewDidLoad() {
super.viewDidLoad()

view.backgroundColor = UIColor.red
}

func didReceive(_ notification: UNNotification) {
Synerise.settings.sdk.appGroupIdentifier = "group.com.synerise.sdk.flutter"
Synerise.settings.sdk.keychainGroupIdentifier = "34N2Z22TKH.FlutterKeychainGroup"

setSyneriseNotification(notification)
}

func didReceive(_ response: UNNotificationResponse, completionHandler completion: @escaping (UNNotificationContentExtensionResponseOption) -> Void) {
setSyneriseNotificationResponse(response, completionHandler: completion)
}
}
Loading

0 comments on commit ab32785

Please sign in to comment.