|
|
1 ay önce | |
|---|---|---|
| .. | ||
| .swiftpm | 1 ay önce | |
| Sources | 1 ay önce | |
| Package.swift | 1 ay önce | |
| README.md | 1 ay önce | |
推送能力层模块,提供推送消息接收和处理能力,可独立打包为 SDK。
CapabilityPush/
├── Package.swift # Swift Package 配置
├── Sources/
│ └── CapabilityPush/
│ ├── CapabilityPush.swift # 模块入口
│ └── Push/
│ ├── Model/
│ │ └── PushConfig.swift # 推送配置模型
│ ├── Impl/
│ │ └── PushServiceImpl.swift # 推送服务实现
│ └── Factory/
│ └── PushServiceFactory.swift # 推送服务工厂
└── Tests/
└── CapabilityPushTests/
// Package.swift 或 Xcode Package Dependencies
dependencies: [
.package(path: "../CapabilityPush"),
.package(path: "../BaseCore")
]
import CapabilityPush
import BaseCore
// 在 AppDelegate 中初始化
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
PushServiceFactory.initialize(
appKey: "your-jpush-appkey",
channel: "App Store",
debugMode: false
)
return true
}
let pushService = PushServiceFactory.create()
// 设置别名
pushService.setAlias("user123")
// 设置标签
pushService.setTags(["vip", "premium"])
// 设置消息监听
pushService.setMessageListener { title, content, extras, messageId in
print("收到消息: \(title) - \(content)")
}
// 注册推送
pushService.register()
本地打包:
cd CapabilityPush
swift build
发布到 Git:
git tag 1.0.0
git push origin 1.0.0
在其他项目中使用:
dependencies: [
.package(url: "https://github.com/your-org/CapabilityPush.git", from: "1.0.0")
]
CapabilityPush 项目创建 CapabilityPush.podspec:
Pod::Spec.new do |s|
s.name = 'CapabilityPush'
s.version = '1.0.0'
s.summary = '推送能力层模块'
s.homepage = 'https://github.com/your-org/CapabilityPush'
s.license = { :type => 'MIT' }
s.author = { 'Your Name' => 'your@email.com' }
s.source = { :git => 'https://github.com/your-org/CapabilityPush.git', :tag => s.version }
s.ios.deployment_target = '15.0'
s.source_files = 'Sources/CapabilityPush/**/*.swift'
s.dependency 'BaseCore'
end
在 Package.swift 中添加依赖:
dependencies: [
.package(url: "https://github.com/jpush/jpush-ios-sdk.git", from: "5.0.0")
]
在 PushServiceImpl.swift 中实现具体逻辑:
```swift
import JPush
// 初始化 JPush.setup(withOption: launchOptions, appKey: appKey, channel: channel, apsForProduction: !debugMode)
// 注册设备 Token JPush.registerDeviceToken(deviceToken)
// 设置别名 JPush.setAlias(alias) { (iResCode, iAlias, seq) in
// 处理结果
} ```
Info.plist 中配置推送权限说明IPushService 接口PushServiceImpl