WiaTagKit 0.60

WiaTagKit 0.60

Gurtam DevelopmentOleg PoroshinAliaksei Verameichyk 维护。



  • wialon

WiaTagKit

Version Platform

示例

要运行示例项目,请克隆仓库,然后首先从 Example 目录运行 pod install

要求

安装

WiaTagKit 通过 CocoaPods 提供。要安装它,只需将以下行添加到 Podfile

pod 'WiaTagKit'
  1. 下载 iOS Worldpay 库

  2. 打开 xcode,创建一个项目,并将 WiaTagKit 库文件夹(iwiatag-kit-ios/WiaTagKit)拖放到 Xcode 项目中

  3. 或者,可以通过运行以下命令重建 Worldpay 库

cd WiaTagKit
pod install --no-integrate

如果您这样做,请确保在之前步辇后拖放 WiaTagKit 库文件夹(如前所述)。

  1. 一个弹出窗口将在 xcode 中打开。请选择以下选项
  • 如果需要,将项复制到目标组文件夹中
  • 为任何添加的文件夹创建组
  • 添加到目标。在此选择您的项目
  1. WiaTagKit iOS 库使用 CocoaAsyncSocket。请确保通过安装 podfile(pod install)将框架安装到您的项目中
pod "CocoaAsyncSocket", "~> 7.6"
  1. 如果你的应用使用 Swift,请确保在完成之前的步骤后,在你的应用中创建一个 桥接头文件。为了这样做,只需创建一个名为 yourprojectname-Bridging-Header.h 的文件,内容如下:
#import "WiaTagSendingLib.h"

完成此操作后,请修改 Target 构建设置中的 "Objective-C 桥接头",以指向你刚刚创建的文件的路径。

使用 Cocoapods 进行安装

WiaTagKit 通过 CocoaPods 提供。要安装它,只需将以下行添加到 Podfile

pod 'WiaTagKit'

如何使用库

  1. 使用 hostportdeviceIdpassword 创建一个 WTMessageManager 对象。
/** OBJECTIVE-C **/
WTMessageManager *sender = [[WTMessageManager alloc] initWithHost:"your_host" port:your_port deviceId:"your_deviceId" password:"your_optional_password"];

/** SWIFT **/
let sender = WTMessageManager(host: "your_host", port: your_port, deviceId: "your_deviceId", password: "your_optional_password")

  1. 创建一个 WTMessage 对象,并在构建块内部进行配置。
/** OBJECTIVE-C **/
WTMessage *msg = [[WTMessage alloc] initWithBlock:^(WTMessageBuilder * _Nonnull builder) {
    builder.time = yourDate;//If you don't specify time, a current date will be used.
    builder.location = [[WTLocation alloc] initWithLocation:yourCoreLocation];
    builder.isSos = YES;//If you don't need send SOS message, you can just skip this propery setting.
    NSData *imageData = UIImageJPEGRepresentation([UIImage imageNamed:imageName], 1);
    if (imageData) {
        builder.image = [[WTImage alloc] initWithImageData:imageData named:imageNameToSend];
    }
    builder.text = yourText;
    builder.batteryLevel = yourBatteryLevel;
    builder.logFileURL = logFileURL; //(json file with file extension .log)
    builder.configFileURL = configFileURL; //(json file with file extension .cfg)
    //If you specify different values with one param name, just one value will be sent. So avoid doing this. 
    [builder addParam:yourTextParamName withText:yourTextParamValue];
    [builder addParam:yourBinaryParamName withBinaryValue:yourBinaryParamValue];
    [builder addParam:yourIntParamName withIntValue:yourIntParamValue];
    [builder addParam:yourFloatParamName withFloatValue:yourFloatParamValue];
    [builder addParam:yourLongParamName withLongValue:yourLongParamValue];
    [builder addParam:yourDoubleParamName withDoubleValue:yourDoubleParamValue];
}];

/** SWIFT **/
let message = WTMessage { builder in
    builder.time = yourDate//If you don't specify time, a current date will be used.
    builder.location = WTLocation(location: yourCoreLocation)
    builder.isSos = true//If you don't need send SOS message, you can just skip this propery setting.
    if let image = UIImage(named: imageName), let imageData = UIImageJPEGRepresentation(image, 1) {
        builder.image = WTImage(imageData: imageData, named: imageNameToSend)
    }
    builder.text = yourText
    builder.batteryLevel = yourBatteryLevel
    builder.logFileURL = logFileURL //(json file with file extension .log)
    builder.configFileURL = configFileURL //(json file with file extension .cfg)
    //If you specify different values with one param name, just one value will be sent. So avoid doing this.
    builder.addParam(yourTextParamName, withText: yourTextParamValue)
    builder.addParam(yourBinaryParamName, withBinaryValue: yourBinaryParamValue)
    builder.addParam(yourIntParamName, withIntValue: yourIntParamValue)
    builder.addParam(yourFloatParamName, withFloatValue: yourFloatParamValue)
    builder.addParam(yourLongParamName, withLongValue: yourLongParamValue)
    builder.addParam(yourDoubleParamName, withDoubleValue: yourDoubleParamValue)    
}

上面示例中的所有属性/方法调用都是可选的。

注意:你也可以以高级方式使用 latitudelongitudealtitudespeedbearingsatellites 创建 WTLocation。

/** OBJECTIVE-C **/
WTLocation *location = [[WTLocation alloc] initWithLatitude:yourLatitude 
                            longitude:aLongitude 
                            altitude:yourAltitude 
                            speed:yourSpeed 
                            bearing:yourBearing 
                            satellites:yourSatellitesCount];

/** SWIFT **/
let location = WTLocation(latitude: yourLatitude, 
                            longitude: yourLongitude, 
                            altitude: yourAltitude, 
                            speed: yourSpeed, 
                            bearing: yourBearing, 
                            satellites: yourSatellitesCount)

  1. 调用方法以发送单个消息(WTMessage)或消息数组(WTMessage 数组)。
/** OBJECTIVE-C **/
//send single message
[sender sendMessage:yourMessage completion:^(NSError * _Nullable error) {
    //Error if nil if message sended with success.
    //Otherwise, you can send your message here.
}];
//send array of messages ([WTMessage])
[self.sender sendMessages:yourArrayOfMessages completion:^(NSError * _Nullable error) {
    //Error if nil if message sended with success.
    //Otherwise, you can send your message here.
}];

/** SWIFT **/
//send single message
sender.send(yourMessage) { error in
    //Error if nil if message sended with success.
    //Otherwise, you can send your message here.
}
//send array of messages ([WTMessage])
sender.send(yourArrayOfMessages) { error in
    //Error if nil if message sended with success.
    //Otherwise, you can send your message here.
}

  1. 如果你想从平台接收消息,需要调用此方法
/** OBJECTIVE-C **/
    [sender enableAllServicesWithCompletion:^(NSError * _Nullable error) {
        //handle error if it is necesary
    }];
    
/** SWIFT **/
    sender.enableAllServices { error in
        //handle error if it is necesary
    }

然后你应该实现任何类型的监听器以适应你的需求

/** OBJECTIVE-C **/
    [sender addListenerWithCompletion:^(id<WTIdentifiable> _Nullable command) {
        //handle command
    }];

/** SWIFT **/
    sender.addListener { command in
        //handle command
    }

最后,你应该手动检查平台的新命令,或者在发送任何命令时有反馈

/** OBJECTIVE-C **/
[sender checkUpdates];

/** SWIFT **/
sender.checkUpdates()
  1. 如果你想从配置器接收配置,需要调用此方法(如果命令执行成功,则不接收任何错误)
/** OBJECTIVE-C **/
    [sender requestConfig:^(NSError * _Nullable error) {
        //handle error if it is necesary
    }];
    
/** SWIFT **/
    sender.requestConfig { error in
        //handle error if it is necesary
    }
  1. 如果你想使用推送通知,需要注册它
/** OBJECTIVE-C **/
    [sender registerForRemoteNotificationsWithServiceName:[[NSBundle mainBundle] bundleIdentifier]
                                                apnsToken:apnsToken
                                                 fcmToken:fcmToken
                                               completion:nil];
/** SWIFT **/
        sender.registerForRemoteNotifications(withServiceName: serviceName,
                                              apnsTokenStringRepresentation: apnsToken,
                                              fcmTokenStringRepresentation: fcmToken,
                                              completion: nil)

如果你想从监听器接收命令,应在 didReceiveRemoteNotification 中处理通知有效负载

/** OBJECTIVE-C **/
    [sender handleRemoteNotificationWithDict:testPushUserInfo
                                  completion:completionHandler];
/** SWIFT **/
    sender.handleRemoteNotification(withDict: info,
                                    completion: completion)
  1. 如果你想同时使用推送通知和 TCP 通道从平台接收消息,你应该在发送器中创建和设置重复检查类。有关详细信息,请参阅 WTBaseCommandDuplicationValidator 类。

作者

Graphic, [email protected]

许可协议

WiaTagKit 在CC BY-ND 4.0许可下可用。更多信息请参阅LICENSE文件。