Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests Apps in both Objective C and Swift #9

Merged
merged 11 commits into from
Aug 25, 2022
Prev Previous commit
Next Next commit
TestApp - Add privacy unknown option + few edits
  • Loading branch information
PravinPK committed Aug 25, 2022
commit 0756d6a3070bbb8c31d66d594229487d49705126
1 change: 0 additions & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pod 'SwiftLint', '0.44.0'
def campaignclassic_dependencies
pod 'AEPCore'
pod 'AEPServices'
pod 'AEPLifecycle'
end

target 'AEPCampaignClassic' do
Expand Down
7 changes: 1 addition & 6 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,31 @@ PODS:
- AEPCore (3.6.0):
- AEPRulesEngine (>= 1.1.0)
- AEPServices (>= 3.6.0)
- AEPLifecycle (3.6.0):
- AEPCore (>= 3.6.0)
- AEPRulesEngine (1.2.0)
- AEPServices (3.6.0)
- SwiftLint (0.44.0)

DEPENDENCIES:
- AEPAssurance
- AEPCore
- AEPLifecycle
- AEPServices
- SwiftLint (= 0.44.0)

SPEC REPOS:
trunk:
- AEPAssurance
- AEPCore
- AEPLifecycle
- AEPRulesEngine
- AEPServices
- SwiftLint

SPEC CHECKSUMS:
AEPAssurance: b25880cd4b14f22c61a1dce19807bd0ca0fe9b17
AEPCore: 03a89f8b792a74e17f739ab535982569d6639b76
AEPLifecycle: 7c0452a650a8ccaaa2473a3625a7004e8687797e
AEPRulesEngine: 71228dfdac24c9ded09be13e3257a7eb22468ccc
AEPServices: fd41aa2d0eda1e6939ae00a99f8431a57d09e1ca
SwiftLint: e96c0a8c770c7ebbc4d36c55baf9096bb65c4584

PODFILE CHECKSUM: 171838047d75847e5df0b8f371dcb695de569da0
PODFILE CHECKSUM: 20a0fb1ffcab557b00c4ed434e3cc998df65cf88

COCOAPODS: 1.11.3
13 changes: 5 additions & 8 deletions TestApp/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,16 @@ import UIKit
import UserNotifications
import AEPCore
import AEPServices
import AEPLifecycle
import AEPAssurance
import AEPCampaignClassic



class AppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDelegate {

var pushDetails = PushNotificationDetailClass()
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we use @StateObject to init PushNotificationDetailClass (which is an ObservableObject)

@StateObject var pushDetails = PushNotificationDetailClass()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No StateObject isn't an ideal choice for use for classes that are not SwiftUI.
We get a warning
"Accessing StateObject's object without being installed on a View. This will create a new instance each time."

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {

MobileCore.setLogLevel(.trace)
let extensions = [Lifecycle.self,
Assurance.self,
let extensions = [Assurance.self,
CampaignClassic.self
]
MobileCore.registerExtensions(extensions, {
Expand All @@ -45,6 +41,7 @@ class AppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDele
center.requestAuthorization(options: [.alert, .sound, .badge, .providesAppNotificationSettings]) { granted, error in
if let error = error {
print("Error retrieving notification permission \(error.localizedDescription)")
PravinPK marked this conversation as resolved.
Show resolved Hide resolved
return
}
guard granted else { return }
self.getNotificationSettings()
Expand All @@ -62,13 +59,13 @@ class AppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDele
}

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
CampaignClassic.registerDevice(token: deviceToken, userKey: "johnDoe", additionalParameters: ["email" : "john@email.com"])
let token = deviceToken.reduce("") {$0 + String(format: "%02X", $1)}
CampaignClassic.registerDevice(token: deviceToken, userKey: "deadpool@swim.com", additionalParameters: nil)
let token = deviceToken.reduce("") {$0 + String(format: "%02x", $1)}
pushDetails.pushToken = token
}

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("Fail to Register for Remote Notification with Error \(error.localizedDescription)")
print("Failed to Register for Remote Notification with Error \(error.localizedDescription)")
}

func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
Expand Down
19 changes: 11 additions & 8 deletions TestApp/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ import AEPCampaignClassic
import UserNotifications

struct ContentView: View {
@EnvironmentObject private var pushDetail: PushNotificationDetailClass
var body: some View {
ScrollView(.vertical, showsIndicators: false) {
Heading()
CampaignClassicMockAPICard()
MobileCorePrivacyAPICard()
NotificationSettingsCard(pushDetail: pushDetail)
NotificationSettingsCard()
}
}
}
Expand All @@ -48,19 +47,23 @@ struct MobileCorePrivacyAPICard: View {
Button("Privacy opt out"){
MobileCore.setPrivacyStatus(PrivacyStatus.optedOut)
}.buttonStyle(CustomButton())

Button("Privacy opt in"){
MobileCore.setPrivacyStatus(PrivacyStatus.optedIn)
}.buttonStyle(CustomButton())
}.padding()
}.padding(.top)
HStack{
Button("Privacy opt Unknown"){
MobileCore.setPrivacyStatus(PrivacyStatus.unknown)
}.buttonStyle(CustomButton())
}.padding(.bottom)
}
}
}

struct NotificationSettingsCard: View {
@State var currentNotificationSettings = ""
@State var unreadNotificationCount = 0
@ObservedObject var pushDetail : PushNotificationDetailClass
@EnvironmentObject private var pushDetail: PushNotificationDetailClass
var body: some View {
VStack {
Spacer(minLength: 20)
Expand Down Expand Up @@ -120,15 +123,15 @@ struct CampaignClassicMockAPICard: View {
Button("Register Device"){
CampaignClassic.registerDevice(token: "6dbc896cf883febf53b2a1c643435bd183c3fdbab35e2bac4310dab23283cd25".data(using: .utf8)!, userKey: "johnDoe", additionalParameters: ["email" : "johnDoe@email.com", "points" : 35773, "isPremiumUser" : true])
}.buttonStyle(CustomButton())

}.padding(.top)
HStack {
Button("Track Receive"){
CampaignClassic.trackNotificationReceive(withUserInfo: ["_mId" : "beca3338-1dd9-4559-ac52-b82ad32c255c", "_dId" : "marketingID"])
}.buttonStyle(CustomButton())

Button("Track Click"){
CampaignClassic.trackNotificationClick(withUserInfo: ["_mId" : "beca3338-1dd9-4559-ac52-b82ad32c255c", "_dId" : "marketingID"])
}.buttonStyle(CustomButton())
}
}.padding(.bottom)
}.padding()
}
}
Expand Down
16 changes: 16 additions & 0 deletions TestAppObjC/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@
<action selector="privacyOptOutClicked:" destination="BYZ-38-t0r" eventType="touchUpInside" id="Exj-ki-dKj"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Rsj-uR-XGC">
<rect key="frame" x="116" y="314" width="158" height="45"/>
<color key="backgroundColor" red="0.19327542189999999" green="0.29907739160000002" blue="0.69953554870000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="45" id="a3I-1w-rTO"/>
</constraints>
<color key="tintColor" red="0.92084878680000004" green="0.93849831819999996" blue="0.97500389809999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<state key="normal" title="Button"/>
<buttonConfiguration key="configuration" style="plain" title="Privacy opt unknown"/>
<connections>
<action selector="privacyOptUnknownClicked:" destination="BYZ-38-t0r" eventType="touchUpInside" id="tgN-Op-A63"/>
</connections>
</button>
</subviews>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
Expand All @@ -83,8 +96,11 @@
<constraint firstItem="DPE-cx-DzZ" firstAttribute="top" secondItem="pW1-Cn-F3P" secondAttribute="bottom" constant="20" id="G32-fs-Td2"/>
<constraint firstItem="74n-Fh-rAa" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" constant="15" id="G8s-7a-sFf"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="qpo-Ye-dxI" secondAttribute="trailing" constant="10" id="N9h-SM-SII"/>
<constraint firstItem="Rsj-uR-XGC" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="116" id="QNd-0I-Ibw"/>
<constraint firstItem="Rsj-uR-XGC" firstAttribute="top" secondItem="DPE-cx-DzZ" secondAttribute="bottom" constant="18" id="bFj-rn-kmt"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="WV2-VA-Aa7" secondAttribute="trailing" constant="25" id="cIs-eb-D0M"/>
<constraint firstItem="74n-Fh-rAa" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="10" id="cca-ng-5cd"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="Rsj-uR-XGC" secondAttribute="trailing" constant="116" id="fIy-Iu-pB9"/>
<constraint firstItem="pW1-Cn-F3P" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="116" id="l0v-hJ-qYU"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="74n-Fh-rAa" secondAttribute="trailing" constant="10" id="uyi-3f-4Sh"/>
<constraint firstItem="qpo-Ye-dxI" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="10" id="xeu-v6-EeJ"/>
Expand Down
4 changes: 4 additions & 0 deletions TestAppObjC/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ - (IBAction)privacyOptInClicked:(id)sender {
[AEPMobileCore setPrivacyStatus:AEPPrivacyStatusOptedIn];
}

- (IBAction)privacyOptUnknownClicked:(id)sender {
[AEPMobileCore setPrivacyStatus:AEPPrivacyStatusUnknown];
}

@end