Skip to content

Barebones example Swift iOS app demonstrating how to use the ParticleSetup / SDK cocoapod libraries

License

Notifications You must be signed in to change notification settings

mrzilvis/example-app-ios

 
 

Repository files navigation

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?

  1. Clone this repo
  2. Open shell window and navigate to project folder
  3. Run pod install
  4. Open ios-app-particle-setup.xcworkspace and run the project on selected device or simulator

How was it created?

  1. Open XCode. File->New->Project->Single View App->Your project name
  2. Create Podfile with your target name and Particle pods reference (see file)
  3. Close XCode Project
  4. Open shell window and navigate to the project folder
  5. Run pod install (make sure your have latest Cocoapods installed), pods will be installed and new XCode workspace file will be created.
  6. in XCode open the new <your project name>.xcworkspace
  7. Add bridging header - see file Particle-Bridging-Header.h for reference.
  8. 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).
  9. Create the source code and storyboard for your app (see ViewController.swift and Main.storyboard for reference)
  10. Build and run - works on simulator and device (no need to do any modifications to Keychain settings)
  11. 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!

About

Barebones example Swift iOS app demonstrating how to use the ParticleSetup / SDK cocoapod libraries

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 79.5%
  • Objective-C 18.8%
  • Ruby 1.7%