To run the example project, clone the repo, and run pod install
from the Example directory first.
iOS 11.0+
Blockstack is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'Blockstack'
You'll need to choose a custom protocol handler that is unique to your app.
This is so that your app's web-based authentication redirect endpoint can redirect the user back to your iOS app.
In this example, we use myblockstackapp://
.
Register your URL scheme in Xcode from the info tab of your project settings.
Blockstack apps are identified by their domain names. You'll need to create an endpoint on the web version of your app that redirects users back to your mobile app.
The endpoint will receive a get request with the query parameter authResponse=XXXX
and should redirect the browser to myblockstackapp://XXXX
.
See the example in the example web app in this repository.
You can run the example webapp to test out redirects by running npm install && npm start
from the webapp directory
Import the Blockstack framework.
import Blockstack
In this example, your web app would be located at http://localhost:8080
Blockstack.shared.signIn(redirectURI: "http://localhost:8080/redirect.html",
appDomain: URL(string: "http://localhost:8080")!) { authResult in
switch authResult {
case .success(let userData):
print("sign in success")
self.handleSignInSuccess(userData: userData)
case .cancelled:
print("sign in cancelled")
case .failed(let error):
print("sign in failed")
print(error!)
}
}
if Blockstack.shared.isSignedIn() {
print("currently signed in")
} else {
print("not signed in")
}
Blockstack.shared.signOut()
let retrievedUserData = Blockstack.shared.loadUserData()
print(retrievedUserData?.profile?.name as Any)
Store data as json on Gaia
Blockstack.shared.putFile(path: "myFile.json", content: content) { (publicURL, error) in
if error != nil {
print("put file error")
} else {
print("put file success \(publicURL!)")
}
}
Read json data from Gaia
Blockstack.shared.getFile(path: "myFile.json", completion: { (response, error) in
if error != nil {
print("get file error")
} else {
print("get file success")
print(response as Any)
}
})
Blockstack PBC