winguSDK-iOS
winguSDK is an iOS SDK for wingu.de service. This framework will allow to connect with beacons and geofences nearby user location. It's written in Swift 3.0
Example
To run the example project, clone the repo, and run pod install
from the Example directory first.
Installation
winguSDK-iOS is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "winguSDK-iOS"
Requirements
Main goal for the SDK is react to surroundings events. wingu SDK is using CoreLocation
to work with beacons and geofences. You'll need to ask user permission to use his location, and it has to be set to always
. Add this key to your .plist
file:
NSLocationAlwaysUsageDescription
And provide an explanation how you want to use user location
Usage
Declaring your key
Call a method
_ = WinguComposition("[YOUR_API_KEY]", false)
The second parameter is for testing enviroment, it will be removed soon. Keep it on false
.
Recommended way to call this method is application:didFinishLaunchingWithOptions
in your AppDelegate
.
Detecting Channels
To connect with nearby locations it's required to respond to protocol WinguLocationsDelegate
. It has required method that will return of a Channel
objects that it's nearby.
To start ranging beacons & geofences add create variable in your class:
var winguLocations: WinguLocations!
and whenever you're ready to range initialize this object:
winguLocations = WinguLocations.sharedInstance
winguLocations.delegate = self
winguLocations.startBeaconsRanging()
Channel
is top level object that can describe beacon or geofence. It can be extended.
For fetching ranged channels in your code add this:
extension ViewController: WinguLocationsDelegate {
func winguRangedChannels(_ channels: [Channel]) {
//do whatever you want with channel objects
}
}
Navigate to Deck
Whenever you got a channel and want to proceed to Deck
you will need to pass an argument. We recommend to use UIStoryboards
and Storyboard Reference
for this, all there you have to do is set Storyboard to WinguDeckStoryboard
and Bundle
to de.wingu.sdk
. Then in prepareForSegue:
method you need to set content
and channelId
like this:
deckVC.content = channel?.content!
deckVC.channelId = channel?.uID
Where deckVC
is WinguDeckViewController
.
If you don't want to use Storyboards, simply get WinguDeckViewController
from WinguDeckStoryboard
and declare transition like you want.
Note:
This will automatically start all analytics. It's recommended to use it like this. Whenever you want to use only view you're responsible to starting and finish the analytics whenever you stop displaying Deck
Custom DeckView
You have full option to customizing your deck with structure DeckComposition
. You can apply it to DeckView
od WinguDeckViewController
. Default is:
DeckComposition(.defaultComposition)
To change for example button background color on ActionComponent
you have to do something like this:
var myComposition = DeckComposition(.defaultComposition)
myComposition.couponComponent.fontColor = UIColor.blue
(winguDectVC as? WinguDeckViewController).composition = myComposition
Background activity
winguSDK can automatically switch from foreground to background activity. All you have to do is declare changing state in your AppDelegate. Then app will turn from ranging beacons to monitoring and other way around:
extension AppDelegate {
func applicationWillResignActive(_ application: UIApplication) {
WinguLocations.applicationState(.willResignActive)
}
func applicationDidEnterBackground(_ application: UIApplication) {
WinguLocations.applicationState(.didEnterBackground)
}
func applicationWillEnterForeground(_ application: UIApplication) {
WinguLocations.applicationState(.willEnterForeground)
}
func applicationDidBecomeActive(_ application: UIApplication) {
WinguLocations.applicationState(.didBecomeActive)
}
func applicationWillTerminate(_ application: UIApplication) {
WinguLocations.applicationState(.willTerminate)
}
}
Use proxy card
To use proxy card you have to make sure that your deck is proxy deck. To check this and in addition check proxy payload use:
channel?.payloadProxy()
Where payloadProxy() is a Channel
object func
that will return your payload id as String
NOTE:
Keep in mind that for that integration is also required to create WinguInteractions
object to collect Analytics.
For this simply use:
self.interactions = self.channel?.startInteractionsMonitoring()
Where self.interactions
is declared as:
var interactions: WinguInteractions?
And to stop interactions call:
self.channel?.stopInteractionsMonitoring(self.interactions!)
Analytics data will be saved locally, to send it, please check the Analytics part
Analytics
When you're using ViewControllers from SDK Analytics are gathered automatically, but you need to send it by hand, to send the analytics put this in your application:didFinishLaunchingWithOptions
method:
Analytics.sendAnalyticsData(nil)
Notifications
To allow notification just call the method:
LocalNotificationManager.setupLocalNotificationManager()
And then handle it with:
func application(_ application: UIApplication, handleActionWithIdentifier identifier: String?, for notification: UILocalNotification, completionHandler: @escaping () -> Void) {
LocalNotificationManager.handleLocalNotificationAction(identifier!)
}
func application(_ application: UIApplication, didReceive notification: UILocalNotification) {
LocalNotificationManager.redirectFromLocalNotificationToChannelDetail(notification, DeckComposition(.defaultComposition))
}
Authors
iOS Developers @ wingu AG
License
winguSDK-iOS is available under the Apache 2.0 license. See the LICENSE file for more info.