CS5530 Mobile/Wireless Systems More on Swift Yanyan Zhuang - - PowerPoint PPT Presentation

cs5530 mobile wireless systems
SMART_READER_LITE
LIVE PREVIEW

CS5530 Mobile/Wireless Systems More on Swift Yanyan Zhuang - - PowerPoint PPT Presentation

CS5530 Mobile/Wireless Systems More on Swift Yanyan Zhuang Department of Computer Science http://www.cs.uccs.edu/~yzhuang UC. Colorado Springs CS5530 Ref. CN5E, NT@UW, WUSTL Overview Optional WiFi interface Location manager


slide-1
SLIDE 1
  • Ref. CN5E, NT@UW, WUSTL

CS5530

CS5530 Mobile/Wireless Systems More on Swift

Yanyan Zhuang

Department of Computer Science http://www.cs.uccs.edu/~yzhuang

  • UC. Colorado Springs
slide-2
SLIDE 2

Overview

  • Ref. CN5E, NT@UW, WUSTL

2 CS5530

  • Optional
  • WiFi interface
  • Location manager
slide-3
SLIDE 3

Optionals

  • Ref. CN5E, NT@UW, WUSTL

3 CS5530

  • Some variables (other than vars or constants)

either have a value, or nil

  • To define an optional
  • var optionalFloat: Float?
  • Optional with forced unwrapping
slide-4
SLIDE 4

WiFi interface

  • Ref. CN5E, NT@UW, WUSTL

4 CS5530

  • interfaces = CNCopySupportedInterfaces()
  • Return all the available interfaces on your device (e.g., en0)
  • As an array
  • interfaceInfo =

CNCopyCurrentNetworkInfo(interfaces)

{ BSSID = "6c:f3:7f:ea:44:f1"; SSID = "UCCS-Wireless"; SSIDDATA = <55434353 2d576972 656c6573 73>; }

slide-5
SLIDE 5

WiFi interface

  • Ref. CN5E, NT@UW, WUSTL

5 CS5530

  • ssid = interfaceInfo[kCNNetworkInfoKeySSID as

String] as? String

  • UCCS-Wireless
  • bssid = interfaceInfo[kCNNetworkInfoKeyBSSID

as String] as? String

  • 6c:f3:7f:ea:44:f1
slide-6
SLIDE 6

Code example

  • Ref. MOS4E, OS@Austin, Columbia, UWisc

6 CS4500/5500

func getSSID() -> String? { var ssid, bssid, info: String? if let interfaces = CNCopySupportedInterfaces() as NSArray? { for interface in interfaces { print(interfaces) if let interfaceInfo = CNCopyCurrentNetworkInfo(interface as! CFString) as NSDictionary? { print(interfaceInfo) ssid = interfaceInfo[kCNNetworkInfoKeySSID as String] as? String bssid = interfaceInfo[kCNNetworkInfoKeyBSSID as String] as? String info = ssid! + ": " + bssid! break } } } return info }

slide-7
SLIDE 7

iOS/Android devices

  • Ref. CN5E, NT@UW, WUSTL

7 CS5530

  • 3 iPhones, 3 iPads
  • 2 Android phones, 2 Android tabs
  • Check out @Ali
slide-8
SLIDE 8

Location Manager

  • Ref. CN5E, NT@UW, WUSTL

8 CS5530

  • Core Location Framework
  • var locationManager: CLLocationManager =

CLLocationManager()

  • Location access permission
  • locationManager.requestWhenInUseAuthorization()
  • locationManager.requestAlwaysAuthorization()