example-app-ios
example-app-ios copied to clipboard
Barebones example Swift iOS app demonstrating how to use the ParticleSetup / SDK cocoapod libraries
iOS Example App
Barebones Swift iOS app showcasing basic ParticleSetup / Particle-SDK cocoapods usage / getting started.
Built using XCode 9.4.1 (Swift 4)
How to run the example?
- Clone this repo
- Open shell window and navigate to project folder
- Run
pod install - Open
ios-app-particle-setup.xcworkspaceand run the project on selected device or simulator
How was it created?
- Open XCode. File->New->Project->Single View App->Your project name
- Create Podfile with your target name and Particle pods reference (see file)
- Close XCode Project
- Open shell window and navigate to the project folder
- Run
pod install(make sure your have latest Cocoapods installed), pods will be installed and new XCode workspace file will be created. - in XCode open the new
<your project name>.xcworkspace - Add bridging header - see file
Particle-Bridging-Header.hfor reference. - Go to project settings->build settings->Objective-C bridging header->type in
./<your project name folder>/Particle-Bridging-Header.h(or wherever file is located). - Create the source code and storyboard for your app (see
ViewController.swiftandMain.storyboardfor reference) - Build and run - works on simulator and device (no need to do any modifications to Keychain settings)
- Click "Start setup" on the phone and onboard a new Photon to your account.
Code
ViewController invoking Particle setup must adhere to the ParticleSetupMainControllerDelegate protocol and implement (at least) the funcion func particleSetupViewController(_ controller: ParticleSetupMainController!, didFinishWith result: ParticleSetupMainControllerResult, device: ParticleDevice!).
To invoke setup:
if let setupController = ParticleSetupMainController()
{
setupController.delegate = self //as! UIViewController & ParticleSetupMainControllerDelegate
self.present(setupController, animated: true, completion: nil)
}
To reference the Particle cloud use: ParticleCloud.sharedInstance(),
to reference a device use: var device : ParticleDevice or use a returned device instance from a cloud function like:
if device != nil
{
device.getVariable("test", completion: { (value, err) -> Void in
print(value)
})
}
For questions - refer to Particle mobile knowledgebase/community here: https://community.particle.io/c/mobile
Good luck!