发送文件到任何位置的 simplest 方法
请先从以下链接获取您的 API密钥: https://send-anywhere.com/web/page/api
为了使用 CocoaPods 将 SendAnywhereSDK 集成到您的 Xcode 项目中,请在其 Podfile
中指定它
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
target 'TargetName' do
pod 'SendAnywhereSDK'
end
然后,运行以下命令
$ pod install
最低iOS目标 | iOS 8 |
---|
如果您在 Send Anywhere iOS SDK 方面有任何问题或疑问,请创建新问题 (https://github.com/estmob/SendAnywhere-iOS-UI-SDK/issues) 或联系我们的客服中心(《(https://send-anywhere.zendesk.com)
首先查看随带的 示例 的源代码。
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
SendAnywhere.withKey("INPUT_YOUR_API_KEY")
return true
}
do {
let viewController = try sa_showSendView(withFiles: [fileURL])
} catch let error {
}
do {
let viewController = try sa_showReceiveView()
} catch let error {
}
// If you want to download files of document type.
SendAnywhere.sharedInstance().downloadFileFilter = [.document]
// If you want to download files of image type.
SendAnywhere.sharedInstance().downloadFileFilter = [.image]
// If you want to download files of audio type.
SendAnywhere.sharedInstance().downloadFileFilter = [.audio]
// If you want to download files of media type.
SendAnywhere.sharedInstance().downloadFileFilter = [.image, .video, .audio]
// If you want to download files of custom file pattern.
SendAnywhere.sharedInstance().customFilePattern = "((.+)(\\.(?i)(jpg|jpeg|png|gif))$)"
if let fileInfo = SAFileInfo(fileName: <fileName>, path: <filePath>, size: <fileSize>, time: <fileTime>, data: <fileData> or nil) {
if let command = SASendCommand.makeInstance() {
command.setParamWith([fileInfo], mode: PAPRIKA_TRANSFER_DIRECT)
command.addPrepareObserver(<observer>)
command.execute(completion: nil)
}
}
key : 6 digit (ex. 348477)
if let command = SAReceiveCommand.makeInstance() {
command.transferType = .receive
command.addErrorObserver(<observer>)
command.addPrepareObserver(<observer>)
command.addNotifyObserver(<observer>)
command.execute(withKey: key)
}
代理 | 描述 |
---|---|
SACommandPrepareDelegate | 更新 authtoken,更新设备 ID |
SACommandNotifyDelegate | 命令启动,完成 |
SACommandErrorDelegate | 命令错误 |
SATransferPrepareDelegate | fileListUpdated,keyUpdated 等 |
SATransferNotifyDelegate | 传输启动,进度,完成等 |
SATransferErrorDelegate | 传输错误 |
SAReceiveErrorDelegate | 接收错误(key不存在,磁盘空间不足等) |
public protocol SAGlobalCommandNotifyDelegate : NSObjectProtocol {
optional public func willGlobalCommandStart(_ sender: SACommand!)
optional public func didGlobalCommandFinish(_ sender: SACommand!)
optional public func didGlobalTransferFileListUpdated(_ sender: SATransferCommand!)
optional public func willGlobalTransferStart(_ sender: SATransferCommand!)
optional public func willGlobalTransferFileStart(_ sender: SATransferCommand!)
optional public func didGlobalTransferFileFinish(_ sender: SATransferCommand!, fileIndex: Int, filePath: String!)
optional public func didGlobalTransferFinish(_ sender: SATransferCommand!)
optional public func didGlobalTransferError(_ sender: SATransferCommand!)
}
SendAnywhereSDK 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。