let datas: [(ability: IBAbility, label: String, parameters: [IBParameter])] = [
+ (.getPushConfig,"获取推送配置",[]),
+ (.setPushConfig,"设置推送",[.setPush(IBPush.all)]),
(.getPasssword,"获取密码",[]),
(.setPasssword,"启用密码",[.setPassword(IBPassword(type: 1, password: "123456"))]),
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
- <key>UIBackgroundModes</key>
- <array>
- <string>bluetooth-central</string>
- </array>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
+ <key>UIBackgroundModes</key>
+ <array>
+ <string>bluetooth-central</string>
+ </array>
</dict>
</plist>
18EFF59B2C080F14001B1E0E /* IBUserInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18EFF59A2C080F14001B1E0E /* IBUserInfo.swift */; };
3F6A07C52D2D06D600F4122A /* MixTools.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3F6A07C42D2D06D600F4122A /* MixTools.framework */; };
3F6A07CC2D2D2C3F00F4122A /* IBPassword.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F6A07CB2D2D2C3F00F4122A /* IBPassword.swift */; };
+ 3F9355B72D38FF2100C54DAB /* IBPush.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F9355B62D38FF1900C54DAB /* IBPush.swift */; };
8A0A39BF2B980BEF006A3B18 /* IOTBluetooth.h in Headers */ = {isa = PBXBuildFile; fileRef = 8A0A39BE2B980BEF006A3B18 /* IOTBluetooth.h */; settings = {ATTRIBUTES = (Public, ); }; };
8A0A39C62B980C88006A3B18 /* IBluetooth.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A0A39C52B980C88006A3B18 /* IBluetooth.swift */; };
8A0A39C92B980CC2006A3B18 /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A0A39C82B980CC2006A3B18 /* CoreBluetooth.framework */; };
18EFF59A2C080F14001B1E0E /* IBUserInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IBUserInfo.swift; sourceTree = "<group>"; };
3F6A07C42D2D06D600F4122A /* MixTools.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = MixTools.framework; sourceTree = "<group>"; };
3F6A07CB2D2D2C3F00F4122A /* IBPassword.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IBPassword.swift; sourceTree = "<group>"; };
+ 3F9355B62D38FF1900C54DAB /* IBPush.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IBPush.swift; sourceTree = "<group>"; };
8A0A39BB2B980BEF006A3B18 /* IOTBluetooth.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = IOTBluetooth.framework; sourceTree = BUILT_PRODUCTS_DIR; };
8A0A39BE2B980BEF006A3B18 /* IOTBluetooth.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IOTBluetooth.h; sourceTree = "<group>"; };
8A0A39C52B980C88006A3B18 /* IBluetooth.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IBluetooth.swift; sourceTree = "<group>"; };
1849DC902BECD131002C2D2D /* IBCode.swift */,
182DDFD32C5CE68900D44D37 /* IBAiValid.swift */,
3F6A07CB2D2D2C3F00F4122A /* IBPassword.swift */,
+ 3F9355B62D38FF1900C54DAB /* IBPush.swift */,
);
path = Models;
sourceTree = "<group>";
buildActionMask = 2147483647;
files = (
8A79D2292BA43F5A0096A98C /* IBResponse.swift in Sources */,
+ 3F9355B72D38FF2100C54DAB /* IBPush.swift in Sources */,
189C15932C05FFA600676A80 /* IBHistoryStand.swift in Sources */,
1849DC8F2BEC8007002C2D2D /* IBVibrateSound.swift in Sources */,
18204C042C199E7800F94E69 /* IBFileSender+Dial.swift in Sources */,
);
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Example/Info.plist;
+ INFOPLIST_KEY_CFBundleDisplayName = IOTBluetooth;
INFOPLIST_KEY_NSBluetoothAlwaysUsageDescription = "扫描智能手表需要开启蓝牙功能";
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
);
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Example/Info.plist;
+ INFOPLIST_KEY_CFBundleDisplayName = IOTBluetooth;
INFOPLIST_KEY_NSBluetoothAlwaysUsageDescription = "扫描智能手表需要开启蓝牙功能";
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
}
public extension IBAbility {
- /// 获取手表密码`
+ /// 获取手表密码
/// - Returns: ``Int`` \
/// Read from ``IBResponse``.value
static let getPasssword = IBAbility.short.id(0x2f).parser(IBGetPasswordParser.self)
/// - Parameter setPassword: see ``IBPassword``
static let setPasssword = IBAbility.long.id(0x1c).parser(IBGeneralParser.self).checker(IBSetPasswordChecker.self)
+ /// 获取消息推送配置
+ /// - Returns: ``[IBPush]`` \
+ /// Read from ``IBResponse``.value
+ static let getPushConfig = IBAbility.short.id(0x33).parser(IBGetPushParser.self)
+
+ /// 设置消息推送
+ /// - Parameter setPush: see ``[IBPush]``
+ static let setPushConfig = IBAbility.long.id(0x1e).parser(IBGeneralParser.self).checker(IBPUshChecker.self)
+
/// 设置用户数据
/// - Parameter userInfo: see ``IBUserInfo``
static let userData = IBAbility.long.id(0x01).parser(IBGeneralParser.self).checker(IBUserInfoChecker.self)
return data
}
}
+struct IBPUshChecker: IBChecker {
+ static func check(_ parameters: [IBParameter]) -> [UInt8] {
+ guard case let .setPush(value) = parameters[.setPush] else { fatalError("缺少参数: setpush") }
+ Logger.log(value.description)
+ var data = [UInt8]()
+ for item in value {
+ data += [item.state.byte]
+ if let value = item.type.bundleId.data(using: .utf8),!value.isEmpty {
+ data += [value.count.byte]
+ data += value.bytes
+ }
+ else{
+ data += [0.byte]
+ }
+ }
+ return data
+ }
+}
struct IBClockChecker: IBChecker {
case aiResponse = "aiResponse"
case setPassword = "setPassword"
+ case setPush = "setPushConfig"
}
/// 参数
case aiResponse(IBAiResponse)
/// 设置密码
case setPassword(IBPassword)
+ /// 设置密码
+ case setPush([IBPush])
var key: IBKey {
switch self {
case .aiValid(_): return .aiValid
case .aiResponse(_): return .aiResponse
case .setPassword(_): return .setPassword
+ case .setPush(_): return .setPush
}
}
}
return .response.code(.success).value(code).message(desc)
}
}
+/// 获取推送配置
+struct IBGetPushParser: IBParser {
+ static func parse(_ data: Data) -> IBResponse {
+ let datas = dataPacket(data)
+ if datas.count == 0{
+ return .response.code(.success).value(IBPush.all)
+ }
+
+ var list = [IBPush]()
+ for i in 0 ..< datas.count {
+ let value = IBPush()
+ value.type = IBPushType(rawValue: i)!
+ value.state = Int(datas[i])
+ list.append(value)
+ }
+
+ return .response.code(.success).value(list)
+ }
+}
struct IBTakePhotoParser: IBParser {
static func parse(_ data: Data) -> IBResponse {
let code = dataPacket(data).int
--- /dev/null
+//
+// IBPush.swift
+// IOTBluetooth
+//
+// Created by liangshi on 2025/1/16.
+//
+
+import Foundation
+/// 关于本机模型
+public class IBPush {
+ /// 类型
+ public var type: IBPushType = .tel
+ /// 0关闭,1开启
+ public var state: Int = 0
+
+ public init() { }
+
+ public init(type:IBPushType,state:Int) {
+ self.type = type
+ self.state = state
+ }
+ var description: String {
+ let str = "IBPush(type: \(type),state:\(state))"
+ return str
+ }
+
+ public static var all:[IBPush]{
+ var list = [IBPush]()
+ for i in 0..<18{
+ let value = IBPush()
+ value.type = IBPushType(rawValue: i)!
+ value.state = i < 10 ? 0:1
+ list.append(value)
+ }
+ return list
+ }
+}
+
+/// 推送配置
+public enum IBPushType: Int {
+ case tel = 0
+ case sms = 1
+ case email = 2
+ case wechat = 3
+ case qq = 4
+ case facebook = 5
+ case twitter = 6
+ case whatsapp = 7
+ case linkedIn = 8
+ case instagram = 9
+ case messenger = 10
+ case snapchat = 11
+ case line = 12
+ case talk = 13
+ case viber = 14
+ case skype = 15
+ case telegram = 16
+ case other = 17
+
+ /// 名字
+ public var name: String{
+ switch self {
+ case .tel:
+ return "电话提醒"
+ case .sms:
+ return "短信提醒"
+ case .email:
+ return "邮件"
+ case .wechat:
+ return "微信"
+ case .qq:
+ return "QQ"
+ case .facebook:
+ return "Facebook"
+ case .twitter:
+ return "Twitter"
+ case .whatsapp:
+ return "Whatsapp"
+ case .linkedIn:
+ return "LinkedIn"
+ case .instagram:
+ return "Instagram"
+ case .messenger:
+ return "Messenger"
+ case .snapchat:
+ return "Snapchat"
+ case .line:
+ return "Line"
+ case .talk:
+ return "Kakao Talk"
+ case .viber:
+ return "Viber"
+ case .skype:
+ return "Skype"
+ case .telegram:
+ return "Telegram"
+ case .other:
+ return "其他"
+ }
+ }
+ /// 包名
+ public var bundleId:String{
+ switch self {
+ case .tel:
+ return "com.apple.mobilephone"
+ case .sms:
+ return "com.apple.MobileSMS"
+ case .email:
+ return "com.netease.mailmaster"
+ case .wechat:
+ return "com.tencent.xin"
+ case .qq:
+ return "com.tencent.mqq"
+ case .facebook:
+ return "com.facebook.Facebook"
+ case .twitter:
+ return "com.atebits.Tweetie2"
+ case .whatsapp:
+ return "net.whatsapp.WhatsAppSMB"
+ case .linkedIn:
+ return "com.linkedin.LinkedIn"
+ case .instagram:
+ return "com.burbn.instagram"
+ case .messenger:
+ return "com.facebook.Messenger"
+ case .snapchat:
+ return "com.toyopagroup.picaboo"
+ case .line:
+ return "jp.naver.line"
+ case .talk:
+ return "com.iwilab.KakaoTalk"
+ case .viber:
+ return "com.viber"
+ case .skype:
+ return "com.skype.skype"
+ case.telegram:
+ return "ph.telegra.Telegraph"
+ default:
+ return "com.others"
+ }
+ }
+}