PCloud
public enum PCloud
Convenience namespace for the SDK. Hosts a global PCloudClient
instance.
-
A global client instance. Automatically initialized either inside
setUp()
orauthorize()
. Access on the main thread only.Declaration
Swift
private(set) public static var sharedClient: PCloudClient?
-
The app key provided in
setUp()
.Declaration
Swift
private(set) public static var appKey: String?
-
Stores the app key and attempts to initialize a pCloud client instance by checking for an existing user in the keychain. The app key is used for the OAuth authorization flow. Generally you should always call this method sometime during app launch. You don’t need to call it if you do not intend to use the OAuth authorization methods provided in this namespace. After this method returns, the
sharedClient
property will be non-nil if there is a user in the keychain. Only call this method once for each instance of your app and only on the main thread.Declaration
Swift
public static func setUp(withAppKey appKey: String)
Parameters
appKey
The app key to initialize the client with.
-
Creates a client object and sets it to the
sharedClient
property. Only call this method on the main thread. Will do nothing if the shared client is already initialized.Parameters
user
A
OAuth.User
value obtained from the keychain or from the OAuth flow. -
Releases the
sharedClient
. You may callinitializeSharedClient()
again after calling this method. Note that this will not stop any running / pending tasks you’ve created using the client. Only call this method on the main thread.Declaration
Swift
public static func clearSharedClient()
-
Releases the
sharedClient
and deletes all user data in the keychain. You may callinitializeSharedClient()
again after calling this method. Note that this will not stop any running / pending tasks you’ve created using the client. Only call this method on the main thread.Declaration
Swift
public static func unlinkAllUsers()
-
Creates a pCloud client. Does not update the
sharedClient
property. You are responsible for storing it and keeping it alive. Use if you want a more direct control over the lifetime of thePCloudClient
object. Multiple clients can exist simultaneously.Declaration
Swift
public static func createClient(with user: OAuth.User) -> PCloudClient
Parameters
user
A
OAuth.User
value obtained from the keychain or the OAuth flow.Return Value
An instance of a
PCloudClient
ready to take requests. -
Starts the OAuth authorization flow. Expects
setUp()
to have been called. Call on the main thread.Declaration
Swift
public static func authorize(with controller: UIViewController, _ completionBlock: @escaping (OAuth.Result) -> Void)
Parameters
controller
A view controller to present a web view from. Must be in the view hierarchy.
completionBlock
A block called on the main thread when authorization completes or is cancelled. The global pCloud client will be initialized inside the block if authorization was successful.