GithubHelp home page GithubHelp logo

cumulocity-open-source / c8y-ios-lib Goto Github PK

View Code? Open in Web Editor NEW

This project forked from johnpcarter/c8y-ios-lib

0.0 0.0 0.0 13.67 MB

iOS swift library to integrate your apps easily with your Cumulocity IoT tenant

Shell 0.02% Objective-C 0.13% Swift 99.85%

c8y-ios-lib's Introduction

README

Client library (iOS 13.0+ or MacOS 10.15+) for accessing your Cumulocity IoT tenant from your own iPhone or Mac apps.

Refer to the Cumulocity Home Page to sign up for your own Cumulocity tenant if you do not already have one.

This library uses the c8y REST API in order to communicate with your tenant and you will need a login with appropriate permissions to allow access.

You will need a Mac (ideally running 10.15) and up to date version of xCode 11.0 to use this library and integrate with your apps.

Install the library direct from github or as a swift package in a xcode project that you have already created.

Using Xcode 11 go to File > Swift Packages > Add Package Dependency Paste the project URL: https://github.com/johnpcarter/c8y-ios-lib Click on next and select the project target, choose latest branch

Now you can import your dependencies e.g.

import Combine
import Cumulocity_Client_Library

Connectivity and basic usage

You first need to create a Connection object and then one of the API Service classes to interact with you Cumulocity tenant, e.g.

let conn: C8yCumulocityConnection = C8yCumulocityConnection(tenant: "<mytenant>", server: "cumulocity.com")

		conn.connect(user: "john", password: "appleseed").sink(receiveCompletion: { (completion) in
				switch completion {
				case .failure(let error):
					print("Connection refused! - \(error.localizedDescription)")
				default:
					print("Connection Success")
					
					// Now that we have tested the connections, lets fetch some managed objects
					
					C8yManagedObjectsService(conn).get(pageNum: 0).sink(receiveCompletion: { (completion) in
					
						switch completion {
						case .failure(let error):
							print("Get Failed \(error.localizedDescription)")
						default:
							print("Get Completed")
						}
						
					}, receiveValue: { results in
					
						if (results.status == .SUCCESS) {
					
							print("page \(results.content!.statistics.currentPage) of \(results.content!.statistics.totalPages!), size \(results.content!.statistics.pageSize)")
					
							for object in results.content!.objects {
									print("\(String(describing: object.id))")
							}
						}
					}).store(in: &self._cancellableSet)
				}
		}, receiveValue: ({ userInfo in
			
			print("User name is \(userInfo)")
			
		})).store(in: &self._cancellableSet)

The above first verifies the connection and uses the C8yManagedObjectsService class to fetch a page of C8yManagedObject objects. The connection object does not carry state and the connect method is only useful to verify the credentials and also gather information about the user C8yUserProfile. Each call via the Service classes reconnects via the connection credentials and is stateless.

SDK Documentation

Full documentation can be viewed here

c8y-ios-lib's People

Contributors

johnpcarter avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.