Skip to content

Commit 590541a

Browse files
1. No need for separate ViewController for setting api key.
2. Prompt for login.
1 parent 0444e63 commit 590541a

File tree

4 files changed

+38
-125
lines changed

4 files changed

+38
-125
lines changed

sample-apps/swift-sample-app/swift-sample-app.xcodeproj/project.pbxproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
ACA3A15120E2F83E00FEF74F /* NotificationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACA3A15020E2F83E00FEF74F /* NotificationService.swift */; };
2222
ACA3A15520E2F83E00FEF74F /* swift-sample-app-notification-extension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = ACA3A14E20E2F83D00FEF74F /* swift-sample-app-notification-extension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
2323
ACE7624B20FEB2C20040A002 /* LoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACE7624A20FEB2C20040A002 /* LoginViewController.swift */; };
24-
ACF0A43A20FE8C50004B59EB /* APIKeyViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACF0A43920FE8C50004B59EB /* APIKeyViewController.swift */; };
2524
/* End PBXBuildFile section */
2625

2726
/* Begin PBXContainerItemProxy section */
@@ -68,7 +67,6 @@
6867
ACA3A15220E2F83E00FEF74F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
6968
ACA3A16420E2FC7500FEF74F /* swift-sample-app.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "swift-sample-app.entitlements"; sourceTree = "<group>"; };
7069
ACE7624A20FEB2C20040A002 /* LoginViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginViewController.swift; sourceTree = "<group>"; };
71-
ACF0A43920FE8C50004B59EB /* APIKeyViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIKeyViewController.swift; sourceTree = "<group>"; };
7270
ACFA148520E3033700AF4A5A /* CoffeeType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoffeeType.swift; sourceTree = "<group>"; };
7371
EE45F561E7E4376F9C089941 /* Pods-swift-sample-app.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-swift-sample-app.release.xcconfig"; path = "Pods/Target Support Files/Pods-swift-sample-app/Pods-swift-sample-app.release.xcconfig"; sourceTree = "<group>"; };
7472
EF740C567615690E8C39C769 /* Pods-swift-sample-app.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-swift-sample-app.debug.xcconfig"; path = "Pods/Target Support Files/Pods-swift-sample-app/Pods-swift-sample-app.debug.xcconfig"; sourceTree = "<group>"; };
@@ -108,7 +106,6 @@
108106
children = (
109107
AC5ECD9E20E304000081E1DA /* CoffeeListTableViewController.swift */,
110108
AC5ECD9F20E304070081E1DA /* CoffeeViewController.swift */,
111-
ACF0A43920FE8C50004B59EB /* APIKeyViewController.swift */,
112109
ACE7624A20FEB2C20040A002 /* LoginViewController.swift */,
113110
);
114111
name = ViewControllers;
@@ -384,7 +381,6 @@
384381
files = (
385382
AC1BDF5A20E304CC000010CA /* CoffeeViewController.swift in Sources */,
386383
ACA3A13920E2F6AF00FEF74F /* AppDelegate.swift in Sources */,
387-
ACF0A43A20FE8C50004B59EB /* APIKeyViewController.swift in Sources */,
388384
AC1BDF5920E304BF000010CA /* DeeplinkHandler.swift in Sources */,
389385
ACE7624B20FEB2C20040A002 /* LoginViewController.swift in Sources */,
390386
AC1BDF5C20E304D7000010CA /* CoffeeType.swift in Sources */,

sample-apps/swift-sample-app/swift-sample-app/APIKeyViewController.swift

Lines changed: 0 additions & 39 deletions
This file was deleted.

sample-apps/swift-sample-app/swift-sample-app/AppDelegate.swift

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,24 @@ import IterableSDK
1515
class AppDelegate: UIResponder, UIApplicationDelegate {
1616
var window: UIWindow?
1717

18+
//ITBL: Set your actual api key here.
19+
let iterableApiKey = ""
20+
1821
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
1922

2023
//ITBL: Setup Notification
2124
setupNotifications()
2225

2326
//ITBL: Initialize API
24-
// NOTE: In your application you should hard-code your Iterable API Key. No need to
25-
// save in UserDefaults
26-
if let iterableApiKey = UserDefaults.standard.string(forKey: "iterableApiKey") {
27-
// You code sould always come here in your actual application
28-
let config = IterableConfig()
29-
config.customActionDelegate = self
30-
config.urlDelegate = self
31-
config.pushIntegrationName = "swift-sample-app"
32-
config.sandboxPushIntegrationName = "swift-sample-app"
33-
// Replace with your api key and email here.
34-
IterableAPI.initialize(apiKey: iterableApiKey,
35-
launchOptions:launchOptions,
36-
config: config)
37-
} else {
38-
// Your code should never come here in your actual application
39-
// For this sample app we don't know the Iterable API Key that's why we have it here.
40-
let storyboard = UIStoryboard(name: "Main", bundle: nil)
41-
let apiKeyVC = storyboard.instantiateViewController(withIdentifier: "APIKeyViewController")
42-
window?.rootViewController = apiKeyVC
43-
}
27+
let config = IterableConfig()
28+
config.customActionDelegate = self
29+
config.urlDelegate = self
30+
config.pushIntegrationName = "swift-sample-app"
31+
config.sandboxPushIntegrationName = "swift-sample-app"
32+
// Replace with your api key and email here.
33+
IterableAPI.initialize(apiKey: iterableApiKey,
34+
launchOptions:launchOptions,
35+
config: config)
4436

4537
return true
4638
}
@@ -61,6 +53,31 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
6153

6254
func applicationDidBecomeActive(_ application: UIApplication) {
6355
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
56+
57+
//ITBL:
58+
// You don't need to do this in your app. Just set the correct value for 'iterableApiKey' when it is declared.
59+
if iterableApiKey == "" {
60+
let alert = UIAlertController(title: "API Key Required", message: "You must set Iterable API Key. Run this app again after setting 'AppDelegate.iterableApiKey'.", preferredStyle: .alert)
61+
let action = UIAlertAction(title: "OK", style: .default) { (action) in
62+
exit(0)
63+
}
64+
alert.addAction(action)
65+
window?.rootViewController?.present(alert, animated: true)
66+
return
67+
}
68+
69+
//ITBL:
70+
if IterableAPI.email == nil {
71+
let alert = UIAlertController(title: "Please Login", message: "You must set 'IterableAPI.email' before receiving push notifications from Iterable.", preferredStyle: .alert)
72+
let action = UIAlertAction(title: "OK", style: .default) { (action) in
73+
let storyboard = UIStoryboard(name: "Main", bundle: nil)
74+
let vc = storyboard.instantiateViewController(withIdentifier: "LoginNavController")
75+
self.window?.rootViewController?.present(vc, animated: true)
76+
}
77+
alert.addAction(action)
78+
window?.rootViewController?.present(alert, animated: true)
79+
return
80+
}
6481
}
6582

6683
func applicationWillTerminate(_ application: UIApplication) {

sample-apps/swift-sample-app/swift-sample-app/Base.lproj/Main.storyboard

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -147,65 +147,6 @@
147147
</objects>
148148
<point key="canvasLocation" x="-1090.4000000000001" y="30.134932533733135"/>
149149
</scene>
150-
<!--APIKey View Controller-->
151-
<scene sceneID="n5t-3t-hlZ">
152-
<objects>
153-
<viewController storyboardIdentifier="APIKeyViewController" id="IO9-oF-X4f" userLabel="APIKey View Controller" customClass="APIKeyViewController" customModule="swift_sample_app" customModuleProvider="target" sceneMemberID="viewController">
154-
<view key="view" contentMode="scaleToFill" id="uk2-mu-eTl">
155-
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
156-
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
157-
<subviews>
158-
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="50" translatesAutoresizingMaskIntoConstraints="NO" id="b45-tb-FE6">
159-
<rect key="frame" x="40" y="170" width="295" height="143"/>
160-
<subviews>
161-
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="iterableLogo" translatesAutoresizingMaskIntoConstraints="NO" id="TRe-GS-hze">
162-
<rect key="frame" x="0.0" y="0.0" width="295" height="33"/>
163-
</imageView>
164-
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="pZu-mp-bL5">
165-
<rect key="frame" x="0.0" y="83" width="295" height="60"/>
166-
<subviews>
167-
<textField opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="249" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="API Key" textAlignment="natural" minimumFontSize="17" clearButtonMode="whileEditing" translatesAutoresizingMaskIntoConstraints="NO" id="c11-r1-P78">
168-
<rect key="frame" x="0.0" y="0.0" width="295" height="30"/>
169-
<nil key="textColor"/>
170-
<fontDescription key="fontDescription" type="system" pointSize="14"/>
171-
<textInputTraits key="textInputTraits" enablesReturnKeyAutomatically="YES" textContentType="email"/>
172-
</textField>
173-
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="leading" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="hGS-b8-YJK">
174-
<rect key="frame" x="0.0" y="30" width="295" height="30"/>
175-
<state key="normal" title="Set API Key">
176-
<color key="titleColor" red="0.96078431369999995" green="0.50196078430000002" blue="0.12549019610000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
177-
</state>
178-
<state key="disabled">
179-
<color key="titleColor" white="0.33333333329999998" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
180-
</state>
181-
<connections>
182-
<action selector="setApiKeyTapped:" destination="IO9-oF-X4f" eventType="touchUpInside" id="RE6-B5-vzU"/>
183-
</connections>
184-
</button>
185-
</subviews>
186-
</stackView>
187-
</subviews>
188-
</stackView>
189-
</subviews>
190-
<color key="backgroundColor" red="0.80000000000000004" green="0.80000000000000004" blue="0.80000000000000004" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
191-
<color key="tintColor" red="0.31372549020000001" green="0.71372549019999998" blue="0.98823529409999999" alpha="1" colorSpace="calibratedRGB"/>
192-
<gestureRecognizers/>
193-
<constraints>
194-
<constraint firstItem="b45-tb-FE6" firstAttribute="top" secondItem="JhS-Sw-BlH" secondAttribute="top" constant="150" id="FhC-EV-Rvk"/>
195-
<constraint firstItem="JhS-Sw-BlH" firstAttribute="trailing" secondItem="b45-tb-FE6" secondAttribute="trailing" constant="40" id="VIu-IE-qfF"/>
196-
<constraint firstItem="b45-tb-FE6" firstAttribute="leading" secondItem="JhS-Sw-BlH" secondAttribute="leading" constant="40" id="lFZ-ZB-vBp"/>
197-
</constraints>
198-
<viewLayoutGuide key="safeArea" id="JhS-Sw-BlH"/>
199-
</view>
200-
<connections>
201-
<outlet property="apiKeyTextField" destination="c11-r1-P78" id="gcl-mJ-Dei"/>
202-
</connections>
203-
</viewController>
204-
<placeholder placeholderIdentifier="IBFirstResponder" id="d6a-8i-De9" sceneMemberID="firstResponder"/>
205-
<tapGestureRecognizer id="yFd-va-2jR"/>
206-
</objects>
207-
<point key="canvasLocation" x="1367" y="30"/>
208-
</scene>
209150
<!--Login View Controller-->
210151
<scene sceneID="Lrp-We-A2i">
211152
<objects>
@@ -231,9 +172,7 @@
231172
</textField>
232173
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="leading" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="8Vl-s0-0tX">
233174
<rect key="frame" x="0.0" y="30" width="295" height="30"/>
234-
<state key="normal" title="Log in">
235-
<color key="titleColor" red="0.96078431369999995" green="0.50196078430000002" blue="0.12549019610000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
236-
</state>
175+
<state key="normal" title="Log in"/>
237176
<state key="disabled">
238177
<color key="titleColor" white="0.33333333329999998" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
239178
</state>

0 commit comments

Comments
 (0)