Skip to content
This repository was archived by the owner on Jul 1, 2019. It is now read-only.

Commit b4ee522

Browse files
committed
auto fill in umber from last app launch
1 parent 068b01c commit b4ee522

File tree

7 files changed

+64
-18
lines changed

7 files changed

+64
-18
lines changed

Example_PushEnabled/VerifyIosSdk_Example_PushEnabled.xcodeproj/project.pbxproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,15 @@
166166
name = check;
167167
sourceTree = "<group>";
168168
};
169-
10845F261DD9F3C900E08158 /* Viewcontroller */ = {
169+
10845F261DD9F3C900E08158 /* ViewController */ = {
170170
isa = PBXGroup;
171171
children = (
172172
2AF474F01BC57BE200FBE0EE /* Main.storyboard */,
173173
2AF474D01BC5798200FBE0EE /* VerifyPageViewController.swift */,
174174
10845F241DD9F3B500E08158 /* start */,
175175
10845F251DD9F3BE00E08158 /* check */,
176176
);
177-
name = Viewcontroller;
177+
name = ViewController;
178178
sourceTree = "<group>";
179179
};
180180
10845F271DD9FB6C00E08158 /* configurator */ = {
@@ -221,7 +221,7 @@
221221
isa = PBXGroup;
222222
children = (
223223
10845F231DD9F3A000E08158 /* Application */,
224-
10845F261DD9F3C900E08158 /* Viewcontroller */,
224+
10845F261DD9F3C900E08158 /* ViewController */,
225225
10845F221DD9F38900E08158 /* Helper */,
226226
10845F211DD9F37E00E08158 /* Supporting Files */,
227227
);

Example_PushEnabled/VerifyIosSdk_Example_PushEnabled/AppDelegate.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,21 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1515
var window: UIWindow?
1616
let configurator = AppConfigurator()
1717

18-
// Your parameters go here! see https://dashboard.nexmo.com/verify
18+
// Your parameters go here, see https://dashboard.nexmo.com/verify/sdk/your-apps
1919
private let applicationId = "YOUR_APP_KEY"
20-
private let sharedSecretKey = "YOUR_SECRET_KEY"
20+
private let secretKey = "YOUR_SECRET_KEY"
2121

2222
// MARK:
2323
// MARK: UIApplicationDelegate - Launch
2424

2525
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
2626
configurator.registerPushNotitications()
27-
28-
NexmoClient.start(applicationId: applicationId, sharedSecretKey: sharedSecretKey)
27+
28+
guard let _ = try? configurator.isClientSetup(applicationId: applicationId, secretKey: secretKey) else {
29+
fatalError("Client not setup, pleae enter your application id and secret key above!")
30+
}
31+
32+
NexmoClient.start(applicationId: applicationId, sharedSecretKey: secretKey)
2933

3034
return true
3135
}
@@ -35,6 +39,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
3539

3640
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
3741
NexmoClient.setPushToken(deviceToken)
42+
print("device token: \(NexmoClient.sharedInstance.pushToken)")
3843
}
3944

4045
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {

Example_PushEnabled/VerifyIosSdk_Example_PushEnabled/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>
22-
<string>4</string>
22+
<string>10</string>
2323
<key>ITSAppUsesNonExemptEncryption</key>
2424
<false/>
2525
<key>LSRequiresIPhoneOS</key>

Example_PushEnabled/VerifyIosSdk_Example_PushEnabled/StartViewController.swift

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ import Foundation
1010
import UIKit
1111
import NexmoVerify
1212

13-
class StartViewController : UIViewController, UIPickerViewDataSource, UIPickerViewDelegate, PageIndexable {
13+
class StartViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate, PageIndexable {
14+
15+
private struct UserSelectedKey {
16+
static let country = "NexmoCountrySelectedKey"
17+
static let phoneNumber = "NexmoPhoneNumberKey"
18+
}
1419

1520
@IBOutlet weak var info: UIButton!
1621
@IBOutlet weak var phoneNumberField: UITextField!
@@ -44,6 +49,7 @@ class StartViewController : UIViewController, UIPickerViewDataSource, UIPickerVi
4449
super.viewDidLoad()
4550

4651
setupView()
52+
setupObserve()
4753
}
4854

4955
// MARK:
@@ -56,8 +62,29 @@ class StartViewController : UIViewController, UIPickerViewDataSource, UIPickerVi
5662
countryPickerView.showsSelectionIndicator = true
5763
countryPickerView.backgroundColor = Colors.nexmoDarkBlue
5864
countryField.inputView = countryPickerView
65+
66+
UserDefaults.standard.synchronize()
67+
68+
// add pre set values
69+
if let country = UserDefaults.standard.value(forKey: UserSelectedKey.country) as? [String : AnyObject], !country.isEmpty {
70+
countryField.text = describeCountry(country)
71+
}
72+
73+
if let number = UserDefaults.standard.value(forKey: UserSelectedKey.phoneNumber) as? String, !number.isEmpty {
74+
phoneNumberField.text = number
75+
}
5976
}
77+
78+
private func setupObserve() {
79+
phoneNumberField.addTarget(self, action: #selector(didEndEditingPhoneNumber(textfield:)), for: .editingDidEnd)
80+
}
81+
82+
// MARK:
83+
// MARK: TextField
6084

85+
func didEndEditingPhoneNumber(textfield: UITextField) {
86+
UserDefaults.standard.set(textfield.text, forKey: UserSelectedKey.phoneNumber)
87+
}
6188

6289
// MARK:
6390
// MARK: Touch
@@ -111,8 +138,6 @@ class StartViewController : UIViewController, UIPickerViewDataSource, UIPickerVi
111138
}))
112139

113140
present(alert, animated: true, completion: nil)
114-
115-
116141
}
117142

118143
// Mark:
@@ -136,6 +161,8 @@ class StartViewController : UIViewController, UIPickerViewDataSource, UIPickerVi
136161
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
137162
currentCountry = Countries.list[row]
138163
countryField.text = describeCountry(currentCountry)
164+
165+
UserDefaults.standard.set(currentCountry, forKey: UserSelectedKey.country)
139166
}
140167

141168
func describeCountry(_ country: [String : AnyObject]) -> String {

Example_PushEnabled/VerifyIosSdk_Example_PushEnabled/configurator/AppConfigurator.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,29 @@ import UIKit
1010

1111
struct AppConfigurator {
1212

13+
internal enum AppError: Error {
14+
case invalidClientSetup
15+
}
16+
1317
// MARK:
1418
// MARK: Notification
1519

16-
func registerPushNotitications() {
20+
internal func registerPushNotitications() {
1721
let settings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
1822

1923
UIApplication.shared.registerUserNotificationSettings(settings)
2024
UIApplication.shared.registerForRemoteNotifications()
2125
}
26+
27+
// MARK:
28+
// MARK: Validation
29+
30+
internal func isClientSetup(applicationId: String, secretKey: String) throws {
31+
guard applicationId != "YOUR_APP_KEY",
32+
secretKey != "YOUR_SECRET_KEY",
33+
!applicationId.isEmpty,
34+
!secretKey.isEmpty else {
35+
throw AppError.invalidClientSetup
36+
}
37+
}
2238
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
app_identifier "com.nexmo.VerifyIosSdk" # The bundle identifier of your app
22
apple_id "[email protected]" # Your Apple email address
3-
team_id "7F2B5ZSP8Q" # Developer Portal Team ID
3+
team_id "118119399" # Developer Portal Team ID
44
team_name "Nexmo Inc."

Example_PushEnabled/fastlane/report.xml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,17 @@
88
</testcase>
99

1010

11-
<testcase classname="fastlane.lanes" name="1: default_platform" time="0.000176">
11+
<testcase classname="fastlane.lanes" name="1: default_platform" time="0.000171">
1212

1313
</testcase>
1414

1515

16-
<testcase classname="fastlane.lanes" name="2: gym" time="41.309175">
16+
<testcase classname="fastlane.lanes" name="2: gym" time="54.79034">
1717

1818
</testcase>
1919

2020

21-
<testcase classname="fastlane.lanes" name="3: pilot" time="858.38996">
22-
23-
<failure message="/Library/Ruby/Gems/2.0.0/gems/fastlane-1.109.0/lib/fastlane/actions/actions_helper.rb:33:in `execute_action'&#10;/Library/Ruby/Gems/2.0.0/gems/fastlane-1.109.0/lib/fastlane/runner.rb:187:in `block in execute_action'&#10;/Library/Ruby/Gems/2.0.0/gems/fastlane-1.109.0/lib/fastlane/runner.rb:186:in `chdir'&#10;/Library/Ruby/Gems/2.0.0/gems/fastlane-1.109.0/lib/fastlane/runner.rb:186:in `execute_action'&#10;/Library/Ruby/Gems/2.0.0/gems/fastlane-1.109.0/lib/fastlane/runner.rb:112:in `trigger_action_by_name'&#10;/Library/Ruby/Gems/2.0.0/gems/fastlane-1.109.0/lib/fastlane/fast_file.rb:146:in `method_missing'&#10;Fastfile:13:in `block (2 levels) in parsing_binding'&#10;/Library/Ruby/Gems/2.0.0/gems/fastlane-1.109.0/lib/fastlane/lane.rb:33:in `call'&#10;/Library/Ruby/Gems/2.0.0/gems/fastlane-1.109.0/lib/fastlane/lane.rb:33:in `call'&#10;/Library/Ruby/Gems/2.0.0/gems/fastlane-1.109.0/lib/fastlane/runner.rb:49:in `block in execute'&#10;/Library/Ruby/Gems/2.0.0/gems/fastlane-1.109.0/lib/fastlane/runner.rb:45:in `chdir'&#10;/Library/Ruby/Gems/2.0.0/gems/fastlane-1.109.0/lib/fastlane/runner.rb:45:in `execute'&#10;/Library/Ruby/Gems/2.0.0/gems/fastlane-1.109.0/lib/fastlane/lane_manager.rb:52:in `cruise_lane'&#10;/Library/Ruby/Gems/2.0.0/gems/fastlane-1.109.0/lib/fastlane/command_line_handler.rb:30:in `handle'&#10;/Library/Ruby/Gems/2.0.0/gems/fastlane-1.109.0/lib/fastlane/commands_generator.rb:95:in `block (2 levels) in run'&#10;/Library/Ruby/Gems/2.0.0/gems/commander-4.4.0/lib/commander/command.rb:178:in `call'&#10;/Library/Ruby/Gems/2.0.0/gems/commander-4.4.0/lib/commander/command.rb:178:in `call'&#10;/Library/Ruby/Gems/2.0.0/gems/commander-4.4.0/lib/commander/command.rb:153:in `run'&#10;/Library/Ruby/Gems/2.0.0/gems/commander-4.4.0/lib/commander/runner.rb:444:in `run_active_command'&#10;/Library/Ruby/Gems/2.0.0/gems/fastlane_core-0.56.0/lib/fastlane_core/ui/fastlane_runner.rb:38:in `run!'&#10;/Library/Ruby/Gems/2.0.0/gems/commander-4.4.0/lib/commander/delegates.rb:15:in `run!'&#10;/Library/Ruby/Gems/2.0.0/gems/fastlane-1.109.0/lib/fastlane/commands_generator.rb:292:in `run'&#10;/Library/Ruby/Gems/2.0.0/gems/fastlane-1.109.0/lib/fastlane/commands_generator.rb:36:in `start'&#10;/Library/Ruby/Gems/2.0.0/gems/fastlane-1.109.0/lib/fastlane/cli_tools_distributor.rb:58:in `take_off'&#10;/Library/Ruby/Gems/2.0.0/gems/fastlane-1.109.0/bin/fastlane:5:in `&lt;top (required)&gt;'&#10;/usr/local/bin/fastlane:23:in `load'&#10;/usr/local/bin/fastlane:23:in `&lt;main&gt;'&#10;&#10;Error receiving the newly uploaded binary, please check iTunes Connect" />
21+
<testcase classname="fastlane.lanes" name="3: pilot" time="633.643141">
2422

2523
</testcase>
2624

0 commit comments

Comments
 (0)