Based on: https://github.com/ipfs-shipyard/swift-ipfs-http-client Converted into a standalone Swift Package.
Add this repo link as a swift package to your XCode project.
- iOS 12 or later
- macOS BigSur or later
import IPFSKit
struct InfuraGateway: IPFSGateway {
var host: IPFSHost {
InfuraHost(id: "...",//On Infura, this is simply the API_KEY
secret: "...")//API_KEY_SECRET
}
var gateway: String {
"https://neatia.infura-ipfs.io"
}
}
IPFSKit.gateway = InfuraGateway()
InfuraHost
is a predefined host that is ready to use:
IPFSKit/Sources/IPFSKit/Models/IPFSHost.swift
Lines 20 to 45 in e0bf830
let data: Data = "Hello World".data(using: .utf8)!
let response = await IPFS.upload(data)
print(IPFSKit.gateway?.url(for: response))
Convert any type of object into a Data
type to prepare for adding.
Infura seems to have updated their services to automatically pin data that is added via the
/add
endpoint (the previous step). This step is uncessary depending on the provider used or edge cases involved.
let data: Data = "Hello World".data(using: .utf8)!
let response = await IPFS.upload(data)
let gatewayHash = await IPFS.pin(response)