这个通用 SOAP 客户端允许您使用 iOS 应用程序、Mac OS X 应用程序和 Apple TV 应用程序访问 Web 服务。
使用此框架,您可以创建支持 SOAP 客户端协议的 iPhone、iPad、Mac OS X 和 Apple TV 应用程序。该框架能够使用 SOAP 标准协议在远程 Web 服务上执行方法。
Swift 4 :该库当前是用 Objective-C 编写的,当您导入 swift 库时,您将收到如下构建错误The use of Swift 3 @objc inference in Swift 4 mode is deprecated
。
对于静默此警告,需要在目标的构建设置中将Swift 3 @objc Inference
设置为默认值。但这还不是全部;用于创建请求的类必须使用@objcMembers
和NSObject
声明,例如:
class MyClass { ... }
let param = MyClass ( )
// ...
// ...
let soap = SOAPEngine ( )
soap . setValue ( param , forKey : " myKey " )
// ...
// ...
MyClass 的声明必须变为:
@ objcMembers class MyClass : NSObject { ... }
从新的 Xcode 8 开始,应用程序需要额外的设置,如果此设置不存在,您将看到如下日志消息:
App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
要解决此问题,请在 info.plist 中添加一些键,步骤如下:
info.plist
文件。NSAppTransportSecurity
的键作为字典。NSAllowsArbitraryLoads
的子项作为 Boolean,并将其值设置为 YES,如下图所示。 参考链接:http://stackoverflow.com/a/32631185/4069848
与代表:
import SOAPEngine64
class ViewController : UIViewController , SOAPEngineDelegate {
var soap : SOAPEngine = SOAPENgine ( )
override func viewDidLoad ( ) {
soap . delegate = self
soap . actionNamespaceSlash = true
soap . setValue ( " Genesis " , forKey : " BookName " )
soap . setIntegerValue ( 1 , forKey : " chapter " )
// standard soap service (.asmx)
soap . requestURL ( " http://www.prioregroup.com/services/americanbible.asmx " ,
soapAction : " http://www.prioregroup.com/GetVerses " )
}
func soapEngine ( _ soapEngine : SOAPEngine ! , didFinishLoadingWith dict : [ AnyHashable : Any ] ! , data : Data ! )
{
let dict = soapEngine . dictionaryValue ( )
print ( dict )
}
}
使用块编程:
import SOAPEngine64
class ViewController : UIViewController {
var soap : SOAPEngine = SOAPENgine ( )
override func viewDidLoad ( ) {
super . viewDidLoad ( )
soap . actionNamespaceSlash = true
soap . setValue ( " Genesis " , forKey : " BookName " )
soap . setIntegerValue ( 1 , forKey : " chapter " )
soap . requestURL ( " http://www.prioregroup.com/services/americanbible.asmx " ,
soapAction : " http://www.prioregroup.com/GetVerses " ,
completeWithDictionary : { ( statusCode : Int ? , dict : [ AnyHashable : Any ] ? ) -> Void in
let book : NSDictionary = dict! as NSDictionary
let verses = book [ " BibleBookChapterVerse " ] as! NSArray
print ( verses )
} ) { ( error : Error ? ) -> Void in
print ( error! )
}
}
}
带有通知:
import SOAPEngine64
class ViewController : UIViewController {
var soap : SOAPEngine = SOAPENgine ( )
override func viewDidLoad ( ) {
super . viewDidLoad ( )
NotificationCenter . default . addObserver ( self ,
selector : #selector ( soapEngineDidFinishLoading ( _ : ) ) ,
name : NSNotification . Name . SOAPEngineDidFinishLoading ,
object : nil )
soap . actionNamespaceSlash = true
soap . setValue ( " Genesis " , forKey : " BookName " )
soap . setIntegerValue ( 1 , forKey : " chapter " )
// standard soap service (.asmx)
soap . requestURL ( " http://www.prioregroup.com/services/americanbible.asmx " ,
soapAction : " http://www.prioregroup.com/GetVerses " )
}
@ objc func soapEngineDidFinishLoading ( _ notification : NSNotification ) {
let engine = notification . object as? SOAPEngine
let dict = engine ( )
print ( dict )
}
}
同步请求:
import SOAPEngine64
class ViewController : UIViewController {
var soap : SOAPEngine = SOAPENgine ( )
override func viewDidLoad ( ) {
super . viewDidLoad ( )
soap . actionNamespaceSlash = true
soap . setValue ( " Genesis " , forKey : " BookName " )
soap . setIntegerValue ( 1 , forKey : " chapter " )
// standard soap service (.asmx)
do {
let result = try soap . syncRequestURL ( " http://www.prioregroup.com/services/americanbible.asmx " ,
soapAction : " http://www.prioregroup.com/GetVerses " )
print ( result )
}
catch {
print ( error )
}
}
}
SOAP 身份验证的设置:
soap . authorizationMethod = . AUTH_BASICAUTH; // basic auth
soap . username = " my-username " ;
soap . password = " my-password " ;
社交OAuth2.0令牌的设置:
// token authorization
soap . authorizationMethod = . AUTH_SOCIAL;
soap . apiKey = " 1234567890 " ; // your apikey https://dev.twitter.com/
soap . socialName = ACAccountTypeIdentifierTwitter; // import Accounts
无需 SSL/HTTPS 的加密/解密数据:
soap . encryptionType = . _ENCRYPT_AES256; // or SOAP_ENCRYPT_3DES
soap . encryptionPassword = " my-password " ;
带有属性的参数:
// book
var book = [ " name " : " Genesis " ] as! NSMutableDictionary
var attr = [ " order " : " asc " ]
// chapter
var child = soap . dictionary ( forKey : " chapter " , value : " 1 " , attributes : attr )
book . addEntries ( from : child! )
// book attributes
soap . setValue ( book , forKey : " Book " , attributes : [ " rack " : " 2 " ] )
它构建一个像这样的请求:
< Book rack = " 2 " >
< name >Genesis name >
< chapter order = " asc " >1 chapter >
Book >
首先,如果您注意到请求响应速度变慢,请尝试更改名为actionNamespaceSlash
属性的值。之后,当使用名为requestWSDL
的方法时,将执行三个步骤:
这没有优化,非常慢,您可以使用以下优化:
SOAPEngine 可作为 Swift 包使用。存储库 URL 对于通过 Xcode 在应用程序中添加包有效。
阅读“入门”指南
阅读将 SOAPEngine 与 Swift 项目集成
阅读“标准安装”指南
审判 只是模拟器 | 单一应用程序 单包 ID | 企业 多捆绑 ID |
---|---|---|
下载 | 购买 12,99€ | 购买 77,47€ |