swiftUI 怎么集成jpush

用户2796711
2021-09-01 07:48 354 1

我已做的尝试:
首先https://github.com/jpush/jpush-swift-demo 提供的demo,发现4.5年没有更新。
我使用pods的方式

pod 'JCore', '2.1.4-noidfa'
pod 'JPush', '3.2.6'

引入

bridging-header 已经创建好,并写好了

#import "JPUSHService.h"

接下来要设置appdelegate

因为当前我创建的项目是直接App.swift,没有appdelegate,因此创建了一个文件。
在app.swift里面加入了
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

请问下在appdelegate里面要怎么写?是需要继承 JPUSHRegisterDelegate ?demo那个引入有错误,方法过期。

我目前写的AppDelegate

class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        JPUSHService.register(forRemoteNotificationTypes: JPAuthorizationOptions.alert.rawValue | JPAuthorizationOptions.badge.rawValue | JPAuthorizationOptions.sound.rawValue , categories: nil)
        JPUSHService.setup(withOption: launchOptions, appKey: appKey, channel: channel, apsForProduction: isProduction)

        return true
    }


    func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
        return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
    }

    func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
    }

    private func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
        print("get the deviceToken  \(deviceToken)")
        JPUSHService.registerDeviceToken(deviceToken as Data)
    }
}

目前 还未集成成功
null

1个回答

热门排序
gptbots-widget