Skip to content

Commit d0c036f

Browse files
committed
Update to iOS 3.0
1 parent 874fd33 commit d0c036f

File tree

3 files changed

+44
-42
lines changed

3 files changed

+44
-42
lines changed

ios-example-app-swift/ios-example-app.xcodeproj/project.pbxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
TargetAttributes = {
128128
E94A9A181BBC0ACA00B8F862 = {
129129
CreatedOnToolsVersion = 7.0;
130+
LastSwiftMigration = 0830;
130131
SystemCapabilities = {
131132
com.apple.BackgroundModes = {
132133
enabled = 1;
@@ -293,6 +294,7 @@
293294
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
294295
PRODUCT_BUNDLE_IDENTIFIER = "ch.freshbits.ios-example-app";
295296
PRODUCT_NAME = "$(TARGET_NAME)";
297+
SWIFT_VERSION = 3.0;
296298
};
297299
name = Debug;
298300
};
@@ -309,6 +311,7 @@
309311
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
310312
PRODUCT_BUNDLE_IDENTIFIER = "ch.freshbits.ios-example-app";
311313
PRODUCT_NAME = "$(TARGET_NAME)";
314+
SWIFT_VERSION = 3.0;
312315
};
313316
name = Release;
314317
};

ios-example-app-swift/ios-example-app/AppDelegate.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,25 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1414

1515
var window: UIWindow?
1616

17-
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
17+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
1818
initPathshare()
1919
return true
2020
}
2121

22-
func applicationWillResignActive(application: UIApplication) {}
22+
func applicationWillResignActive(_ application: UIApplication) {}
2323

24-
func applicationDidEnterBackground(application: UIApplication) {}
24+
func applicationDidEnterBackground(_ application: UIApplication) {}
2525

26-
func applicationWillEnterForeground(application: UIApplication) {}
26+
func applicationWillEnterForeground(_ application: UIApplication) {}
2727

28-
func applicationDidBecomeActive(application: UIApplication) {}
28+
func applicationDidBecomeActive(_ application: UIApplication) {}
2929

30-
func applicationWillTerminate(application: UIApplication) {}
30+
func applicationWillTerminate(_ application: UIApplication) {}
3131

32-
private func initPathshare() {
33-
let pathshare = NSBundle.mainBundle().pathForResource("Pathshare", ofType:"plist") as String!
34-
let config = NSDictionary(contentsOfFile: pathshare) as NSDictionary!
35-
Pathshare.setAccountToken(config!.valueForKey("account_token") as! String)
32+
fileprivate func initPathshare() {
33+
let pathshare = Bundle.main.path(forResource: "Pathshare", ofType:"plist") as String!
34+
let config = NSDictionary(contentsOfFile: pathshare!) as NSDictionary!
35+
Pathshare.setAccountToken(config!.value(forKey: "account_token") as! String)
3636
}
3737

3838
}

ios-example-app-swift/ios-example-app/ViewController.swift

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ class ViewController: UIViewController, SessionExpirationDelegate {
2424
findSession()
2525
}
2626

27-
private func initButtons() {
28-
self.joinButton?.enabled = false
29-
self.leaveButton?.enabled = false
27+
fileprivate func initButtons() {
28+
self.joinButton?.isEnabled = false
29+
self.leaveButton?.isEnabled = false
3030
}
3131

3232
// MARK: IBActions
3333

34-
@IBAction func createSession(sender: AnyObject) {
34+
@IBAction func createSession(_ sender: AnyObject) {
3535
Pathshare.saveUserName("SDK User ios") { (error) -> Void in
3636
if error != nil {
3737
NSLog("User: Error")
@@ -43,46 +43,46 @@ class ViewController: UIViewController, SessionExpirationDelegate {
4343
}
4444
}
4545

46-
@IBAction func joinSession(sender: AnyObject) {
46+
@IBAction func joinSession(_ sender: AnyObject) {
4747
self.session.joinUser { (error) -> Void in
4848
if error != nil {
4949
NSLog("Session Join: Error")
5050
NSLog(error.description)
5151
} else {
5252
NSLog("Session Join: Success")
53-
self.createButton?.enabled = false
54-
self.joinButton?.enabled = false
55-
self.leaveButton?.enabled = true
53+
self.createButton?.isEnabled = false
54+
self.joinButton?.isEnabled = false
55+
self.leaveButton?.isEnabled = true
5656
}
5757
}
5858
}
5959

60-
@IBAction func leaveSesson(sender: AnyObject) {
60+
@IBAction func leaveSesson(_ sender: AnyObject) {
6161
self.session.leaveUser { (error) -> Void in
6262
if error != nil {
6363
NSLog("Session Leave: Error")
6464
NSLog(error.description)
6565
} else {
6666
NSLog("Session Leave: Success")
67-
self.leaveButton?.enabled = false
68-
self.createButton?.enabled = true
67+
self.leaveButton?.isEnabled = false
68+
self.createButton?.isEnabled = true
6969

7070
self.deleteSessionIdentifier()
7171
}
7272
}
7373
}
7474

75-
private func createSession() {
75+
fileprivate func createSession() {
7676
let destination = Destination()
7777
destination.identifier = "store1234"
7878
destination.latitude = 47.378178
7979
destination.longitude = 8.539256
8080

8181
self.session = Session()
8282
self.session.name = "Example Session ios"
83-
self.session.expirationDate = NSDate(timeIntervalSinceNow: 3600)
83+
self.session.expirationDate = Date(timeIntervalSinceNow: 3600)
8484
self.session.destination = destination
85-
self.session.trackingMode = PSTrackingMode.Smart
85+
self.session.trackingMode = PSTrackingMode.smart
8686
self.session.delegate = self
8787

8888
self.session.save { (error: NSError!) -> Void in
@@ -91,45 +91,44 @@ class ViewController: UIViewController, SessionExpirationDelegate {
9191
NSLog(error.description)
9292
} else {
9393
NSLog("Session: Success")
94-
self.joinButton?.enabled = true
95-
self.createButton?.enabled = false
94+
self.joinButton?.isEnabled = true
95+
self.createButton?.isEnabled = false
9696

9797
self.saveSessionIdentifier()
9898
}
99-
}
99+
} as! (Error?) -> Void as! (Error?) -> Void as! (Error?) -> Void as! (Error?) -> Void as! (Error?) -> Void as! (Error?) -> Void as! (Error?) -> Void
100100
}
101101

102-
private func findSession() {
103-
let sessionIdentifier = NSUserDefaults.standardUserDefaults().objectForKey(sessionIdentifierKey) as? String
102+
fileprivate func findSession() {
103+
let sessionIdentifier = UserDefaults.standard.object(forKey: sessionIdentifierKey) as? String
104104

105105
guard sessionIdentifier != nil else { return }
106106

107-
Pathshare .findSessionWithIdentifier(sessionIdentifier) { (session, error) -> Void in
107+
Pathshare .findSession(withIdentifier: sessionIdentifier) { (session, error) -> Void in
108108
if session != nil {
109-
session.delegate = self
109+
session?.delegate = self
110110
self.session = session
111111

112-
self.createButton.enabled = false;
113-
self.joinButton.enabled = true;
114-
self.leaveButton.enabled = false;
112+
self.createButton.isEnabled = false;
113+
self.joinButton.isEnabled = true;
114+
self.leaveButton.isEnabled = false;
115115
}
116116
}
117117
}
118118

119-
private func saveSessionIdentifier() {
120-
NSUserDefaults.standardUserDefaults().setObject(self.session.identifier, forKey: sessionIdentifierKey)
119+
fileprivate func saveSessionIdentifier() {
120+
UserDefaults.standard.set(self.session.identifier, forKey: sessionIdentifierKey)
121121
}
122122

123-
private func deleteSessionIdentifier() {
124-
NSUserDefaults.standardUserDefaults().removeObjectForKey(sessionIdentifierKey)
123+
fileprivate func deleteSessionIdentifier() {
124+
UserDefaults.standard.removeObject(forKey: sessionIdentifierKey)
125125
}
126126

127127
// MARK: SessionExpirationDelegate
128128

129129
func sessionDidExpire() {
130-
self.leaveButton?.enabled = false
131-
self.joinButton?.enabled = false
132-
self.createButton?.enabled = true
130+
self.leaveButton?.isEnabled = false
131+
self.joinButton?.isEnabled = false
132+
self.createButton?.isEnabled = true
133133
}
134134
}
135-

0 commit comments

Comments
 (0)