-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #355 from CleverTap/develop
Update Example App to support iOS Push Notification
- Loading branch information
Showing
19 changed files
with
1,331 additions
and
10 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
Example/ios/NotificationContent/Base.lproj/MainInterface.storyboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="M4Y-Lb-cyx"> | ||
<device id="retina6_12" orientation="portrait" appearance="light"/> | ||
<dependencies> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21678"/> | ||
<capability name="Safe area layout guides" minToolsVersion="9.0"/> | ||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | ||
</dependencies> | ||
<scenes> | ||
<!--Notification View Controller--> | ||
<scene sceneID="cwh-vc-ff4"> | ||
<objects> | ||
<viewController id="M4Y-Lb-cyx" userLabel="Notification View Controller" customClass="NotificationViewController" sceneMemberID="viewController"> | ||
<view key="view" contentMode="scaleToFill" simulatedAppContext="notificationCenter" id="S3S-Oj-5AN"> | ||
<rect key="frame" x="0.0" y="0.0" width="320" height="37"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<viewLayoutGuide key="safeArea" id="2BE-c3-nQJ"/> | ||
<color key="backgroundColor" red="0.45882353186607361" green="0.74901962280273438" blue="0.66666668653488159" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> | ||
</view> | ||
<extendedEdge key="edgesForExtendedLayout"/> | ||
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/> | ||
<size key="freeformSize" width="320" height="37"/> | ||
</viewController> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="vXp-U4-Rya" userLabel="First Responder" sceneMemberID="firstResponder"/> | ||
</objects> | ||
<point key="canvasLocation" x="101" y="-3"/> | ||
</scene> | ||
</scenes> | ||
</document> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
<string>CTNotification</string> | ||
<key>UNNotificationExtensionInitialContentSizeRatio</key> | ||
<real>0.1</real> | ||
<key>UNNotificationExtensionUserInteractionEnabled</key> | ||
<string>1</string> | ||
<key>UNNotificationExtensionDefaultContentHidden</key> | ||
<true/> | ||
</dict> | ||
<key>NSExtensionMainStoryboard</key> | ||
<string>MainInterface</string> | ||
<key>NSExtensionPointIdentifier</key> | ||
<string>com.apple.usernotifications.content-extension</string> | ||
</dict> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#import <CTNotificationContent/CTNotificationContent.h> | ||
|
||
@interface NotificationViewController : CTNotificationViewController | ||
|
||
@end |
25 changes: 25 additions & 0 deletions
25
Example/ios/NotificationContent/NotificationViewController.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#import "NotificationViewController.h" | ||
|
||
/* | ||
Note: We have added two Notification Content target for Objective-C and Swift only for sample codes. | ||
You can also use multiple Notification Content target at a time, only you need to add different | ||
`UNNotificationExtensionCategory` for each content target as added here in both Info.plist file, | ||
to show different category buttons added in AppDelegate file. | ||
*/ | ||
@implementation NotificationViewController | ||
|
||
- (void)viewDidLoad { | ||
[super viewDidLoad]; | ||
} | ||
|
||
// optional: implement to get user event type data | ||
- (void)userDidPerformAction:(NSString *)action withProperties:(NSDictionary *)properties { | ||
NSLog(@"user did perform action: %@ with props: %@", action , properties); | ||
} | ||
|
||
// optional: implement to get notification response | ||
- (void)userDidReceiveNotificationResponse:(UNNotificationResponse *)response { | ||
NSLog(@"user did receive notification response: %@:", response); | ||
} | ||
|
||
@end |
29 changes: 29 additions & 0 deletions
29
Example/ios/NotificationContentSwift/Base.lproj/MainInterface.storyboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="M4Y-Lb-cyx"> | ||
<device id="retina6_12" orientation="portrait" appearance="light"/> | ||
<dependencies> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21678"/> | ||
<capability name="Safe area layout guides" minToolsVersion="9.0"/> | ||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | ||
</dependencies> | ||
<scenes> | ||
<!--Notification View Controller--> | ||
<scene sceneID="cwh-vc-ff4"> | ||
<objects> | ||
<viewController id="M4Y-Lb-cyx" userLabel="Notification View Controller" customClass="NotificationViewController" customModule="NotificationContentSwift" customModuleProvider="target" sceneMemberID="viewController"> | ||
<view key="view" contentMode="scaleToFill" simulatedAppContext="notificationCenter" id="S3S-Oj-5AN"> | ||
<rect key="frame" x="0.0" y="0.0" width="320" height="37"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<viewLayoutGuide key="safeArea" id="2BE-c3-nQJ"/> | ||
<color key="backgroundColor" red="0.45882353186607361" green="0.74901962280273438" blue="0.66666668653488159" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> | ||
</view> | ||
<extendedEdge key="edgesForExtendedLayout"/> | ||
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/> | ||
<size key="freeformSize" width="320" height="37"/> | ||
</viewController> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="vXp-U4-Rya" userLabel="First Responder" sceneMemberID="firstResponder"/> | ||
</objects> | ||
<point key="canvasLocation" x="139" y="4"/> | ||
</scene> | ||
</scenes> | ||
</document> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
<string>CTNotification1</string> | ||
<key>UNNotificationExtensionInitialContentSizeRatio</key> | ||
<real>0.1</real> | ||
<key>UNNotificationExtensionUserInteractionEnabled</key> | ||
<string>1</string> | ||
<key>UNNotificationExtensionDefaultContentHidden</key> | ||
<true/> | ||
</dict> | ||
<key>NSExtensionMainStoryboard</key> | ||
<string>MainInterface</string> | ||
<key>NSExtensionPointIdentifier</key> | ||
<string>com.apple.usernotifications.content-extension</string> | ||
</dict> | ||
</dict> | ||
</plist> |
13 changes: 13 additions & 0 deletions
13
Example/ios/NotificationContentSwift/NotificationViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import CTNotificationContent | ||
|
||
/* | ||
Note: We have added two Notification Content target for Objective-C and Swift only for sample codes. | ||
You can also use multiple Notification Content target at a time, only you need to add different | ||
`UNNotificationExtensionCategory` for each content target as added here in both Info.plist file, | ||
to show different category buttons added in AppDelegate file. | ||
*/ | ||
class NotificationViewController: CTNotificationViewController { | ||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?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>CleverTapAccountID</key> | ||
<string>RKW-R77-KW6Z</string> | ||
<key>CleverTapToken</key> | ||
<string>aa2-032</string> | ||
<key>NSExtension</key> | ||
<dict> | ||
<key>NSExtensionPointIdentifier</key> | ||
<string>com.apple.usernotifications.service</string> | ||
<key>NSExtensionPrincipalClass</key> | ||
<string>NotificationService</string> | ||
</dict> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#import <CTNotificationService/CTNotificationService.h> | ||
|
||
@interface NotificationService : CTNotificationServiceExtension | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#import "NotificationService.h" | ||
#import <CleverTap-iOS-SDK/CleverTap.h> | ||
|
||
/* | ||
Note: We have added two Notification Service target for Objective-C and Swift only for sample codes. | ||
You can activate/deactivate other target to use any one at a time. | ||
Steps to add/remove target: Click on Example target -> Build Phases -> Target Dependencies -> Click on add/remove items. | ||
*/ | ||
@implementation NotificationService | ||
|
||
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler { | ||
// Add CleverTap Account ID and Account token in your target .plist file | ||
[CleverTap setDebugLevel:2]; | ||
NSDictionary *profile = @{ | ||
@"Name": @"testUserA1", | ||
@"Identity": @123456, | ||
@"Email": @"[email protected]" | ||
}; | ||
[[CleverTap sharedInstance] profilePush:profile]; | ||
[[CleverTap sharedInstance] recordNotificationViewedEventWithData: request.content.userInfo]; | ||
|
||
[super didReceiveNotificationRequest:request withContentHandler:contentHandler]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?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>CleverTapAccountID</key> | ||
<string>RKW-R77-KW6Z</string> | ||
<key>CleverTapToken</key> | ||
<string>aa2-032</string> | ||
<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> |
19 changes: 19 additions & 0 deletions
19
Example/ios/NotificationServiceSwift/NotificationService.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import CTNotificationService | ||
import CleverTapSDK | ||
|
||
/* | ||
Note: We have added two Notification Service target for Objective-C and Swift only for sample codes. | ||
You can activate/deactivate other target to use any one at a time. | ||
Steps to add/remove target: Click on Example target -> Build Phases -> Target Dependencies -> Click on add/remove items. | ||
*/ | ||
class NotificationService: CTNotificationServiceExtension { | ||
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) { | ||
let profile: Dictionary<String, AnyObject> = [ | ||
"Name": "testUserA1" as AnyObject, | ||
"Identity": 123456 as AnyObject, | ||
"Email": "[email protected]" as AnyObject ] | ||
CleverTap.sharedInstance()?.profilePush(profile) | ||
CleverTap.sharedInstance()?.recordNotificationViewedEvent(withData: request.content.userInfo) | ||
super.didReceive(request, withContentHandler: contentHandler) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.