From: liangzhenying <867174124@qq.com> Date: Fri, 17 Jan 2025 02:36:06 +0000 (+0800) Subject: 新增消息推送指令 X-Git-Url: http://git.snicker.com.cn/sitemap.xml?a=commitdiff_plain;h=faa42b1ea1fbaf8981cf4cbebff370505674c6e3;p=mirrors%2FIOTBluetooth-iOS.git 新增消息推送指令 --- diff --git a/IOTBluetooth/IOTBluetooth/Example/Datas.swift b/IOTBluetooth/IOTBluetooth/Example/Datas.swift index ffdd68a..867831f 100644 --- a/IOTBluetooth/IOTBluetooth/Example/Datas.swift +++ b/IOTBluetooth/IOTBluetooth/Example/Datas.swift @@ -12,6 +12,8 @@ import IOTBluetooth let datas: [(ability: IBAbility, label: String, parameters: [IBParameter])] = [ + (.getPushConfig,"获取推送配置",[]), + (.setPushConfig,"设置推送",[.setPush(IBPush.all)]), (.getPasssword,"获取密码",[]), (.setPasssword,"启用密码",[.setPassword(IBPassword(type: 1, password: "123456"))]), diff --git a/IOTBluetooth/IOTBluetooth/Example/Info.plist b/IOTBluetooth/IOTBluetooth/Example/Info.plist index 1ec584a..317fec1 100644 --- a/IOTBluetooth/IOTBluetooth/Example/Info.plist +++ b/IOTBluetooth/IOTBluetooth/Example/Info.plist @@ -2,14 +2,14 @@ - UIBackgroundModes - - bluetooth-central - NSAppTransportSecurity NSAllowsArbitraryLoads + UIBackgroundModes + + bluetooth-central + diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcodeproj/project.pbxproj b/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcodeproj/project.pbxproj index 09c1c8a..8f5c54e 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcodeproj/project.pbxproj +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcodeproj/project.pbxproj @@ -62,6 +62,7 @@ 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 */; }; @@ -183,6 +184,7 @@ 18EFF59A2C080F14001B1E0E /* IBUserInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IBUserInfo.swift; sourceTree = ""; }; 3F6A07C42D2D06D600F4122A /* MixTools.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = MixTools.framework; sourceTree = ""; }; 3F6A07CB2D2D2C3F00F4122A /* IBPassword.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IBPassword.swift; sourceTree = ""; }; + 3F9355B62D38FF1900C54DAB /* IBPush.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IBPush.swift; sourceTree = ""; }; 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 = ""; }; 8A0A39C52B980C88006A3B18 /* IBluetooth.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IBluetooth.swift; sourceTree = ""; }; @@ -405,6 +407,7 @@ 1849DC902BECD131002C2D2D /* IBCode.swift */, 182DDFD32C5CE68900D44D37 /* IBAiValid.swift */, 3F6A07CB2D2D2C3F00F4122A /* IBPassword.swift */, + 3F9355B62D38FF1900C54DAB /* IBPush.swift */, ); path = Models; sourceTree = ""; @@ -530,6 +533,7 @@ 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 */, @@ -870,6 +874,7 @@ ); GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = Example/Info.plist; + INFOPLIST_KEY_CFBundleDisplayName = IOTBluetooth; INFOPLIST_KEY_NSBluetoothAlwaysUsageDescription = "扫描智能手表需要开启蓝牙功能"; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; @@ -908,6 +913,7 @@ ); GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = Example/Info.plist; + INFOPLIST_KEY_CFBundleDisplayName = IOTBluetooth; INFOPLIST_KEY_NSBluetoothAlwaysUsageDescription = "扫描智能手表需要开启蓝牙功能"; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcodeproj/project.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate b/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcodeproj/project.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate index aca58d4..f2903ef 100644 Binary files a/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcodeproj/project.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate and b/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcodeproj/project.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBAbility.swift b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBAbility.swift index 209fb35..cd782cc 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBAbility.swift +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBAbility.swift @@ -82,7 +82,7 @@ extension IBAbility { } public extension IBAbility { - /// 获取手表密码` + /// 获取手表密码 /// - Returns: ``Int`` \ /// Read from ``IBResponse``.value static let getPasssword = IBAbility.short.id(0x2f).parser(IBGetPasswordParser.self) @@ -90,6 +90,15 @@ public extension IBAbility { /// - 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) diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBChecker.swift b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBChecker.swift index de9edb8..93e6c3c 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBChecker.swift +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBChecker.swift @@ -294,6 +294,24 @@ struct IBUserInfoChecker: IBChecker { 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 { diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBParameter.swift b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBParameter.swift index c27b866..e01be3f 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBParameter.swift +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBParameter.swift @@ -41,6 +41,7 @@ enum IBKey: String { case aiResponse = "aiResponse" case setPassword = "setPassword" + case setPush = "setPushConfig" } /// 参数 @@ -109,6 +110,8 @@ public enum IBParameter { case aiResponse(IBAiResponse) /// 设置密码 case setPassword(IBPassword) + /// 设置密码 + case setPush([IBPush]) var key: IBKey { switch self { @@ -144,6 +147,7 @@ public enum IBParameter { case .aiValid(_): return .aiValid case .aiResponse(_): return .aiResponse case .setPassword(_): return .setPassword + case .setPush(_): return .setPush } } } diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBParser.swift b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBParser.swift index b24bf46..55b0414 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBParser.swift +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBParser.swift @@ -78,6 +78,25 @@ struct IBGetPasswordParser: IBParser { 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 diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth/Models/IBPush.swift b/IOTBluetooth/IOTBluetooth/IOTBluetooth/Models/IBPush.swift new file mode 100644 index 0000000..04fde22 --- /dev/null +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth/Models/IBPush.swift @@ -0,0 +1,142 @@ +// +// 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" + } + } +}