wangmeng 6ab7c597b4 Initial commit: iOS项目 1 月之前
..
.swiftpm 6ab7c597b4 Initial commit: iOS项目 1 月之前
Sources 6ab7c597b4 Initial commit: iOS项目 1 月之前
Package.swift 6ab7c597b4 Initial commit: iOS项目 1 月之前
README.md 6ab7c597b4 Initial commit: iOS项目 1 月之前

README.md

CapabilityPush - iOS 推送能力层

推送能力层模块,提供推送消息接收和处理能力,可独立打包为 SDK。

📦 模块结构

CapabilityPush/
├── Package.swift              # Swift Package 配置
├── Sources/
│   └── CapabilityPush/
│       ├── CapabilityPush.swift      # 模块入口
│       └── Push/
│           ├── Model/
│           │   └── PushConfig.swift  # 推送配置模型
│           ├── Impl/
│           │   └── PushServiceImpl.swift  # 推送服务实现
│           └── Factory/
│               └── PushServiceFactory.swift  # 推送服务工厂
└── Tests/
    └── CapabilityPushTests/

🔗 依赖关系

  • BaseCore: 依赖本地 BaseCore 模块(提供 IPushService 接口和 ILog)

📝 使用方式

1. 在 Xcode 项目中添加依赖

// Package.swift 或 Xcode Package Dependencies
dependencies: [
    .package(path: "../CapabilityPush"),
    .package(path: "../BaseCore")
]

2. 初始化推送服务

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
}

3. 使用推送服务

let pushService = PushServiceFactory.create()

// 设置别名
pushService.setAlias("user123")

// 设置标签
pushService.setTags(["vip", "premium"])

// 设置消息监听
pushService.setMessageListener { title, content, extras, messageId in
    print("收到消息: \(title) - \(content)")
}

// 注册推送
pushService.register()

📦 单独打包 SDK

方式一:使用 Swift Package Manager

  1. 本地打包

    cd CapabilityPush
    swift build
    
  2. 发布到 Git

    git tag 1.0.0
    git push origin 1.0.0
    
  3. 在其他项目中使用

    dependencies: [
    .package(url: "https://github.com/your-org/CapabilityPush.git", from: "1.0.0")
    ]
    

方式二:使用 Xcode Archive

  1. 在 Xcode 中打开 CapabilityPush 项目
  2. Product → Archive
  3. 导出为 Framework 或 XCFramework

方式三:使用 CocoaPods(可选)

创建 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

🔧 集成第三方 SDK

集成 JPush iOS SDK

  1. Package.swift 中添加依赖:

    dependencies: [
    .package(url: "https://github.com/jpush/jpush-ios-sdk.git", from: "5.0.0")
    ]
    
  2. 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

// 处理结果

} ```

📋 注意事项

  1. 依赖管理:确保 BaseCore 已正确配置
  2. 权限配置:在 Info.plist 中配置推送权限说明
  3. AppDelegate 集成:需要在 AppDelegate 中处理 APNs 回调
  4. 测试:集成 JPush SDK 后需要真机测试

🏗️ 架构说明

  • 接口定义:在 BaseCore 中定义 IPushService 接口
  • 实现类:在 CapabilityPush 中实现 PushServiceImpl
  • 解耦设计:通过接口实现 BaseCore 与 CapabilityPush 的解耦
  • 独立打包:每个能力层都是独立的 Swift Package,可以单独打包和发布