Commit 31972f3c authored by Steven杜宇's avatar Steven杜宇

// 出行推送

parent 1334471c
......@@ -6,21 +6,19 @@
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
import AuthenticationServices
import UIKit
extension AppDelegate: JPUSHRegisterDelegate {
// 注册JPush服务
func registerJPushService(_ launchOptions: [UIApplication.LaunchOptionsKey: Any]?) {
let entity: JPUSHRegisterEntity = JPUSHRegisterEntity()
entity.types = Int(JPAuthorizationOptions.alert.rawValue |
JPAuthorizationOptions.badge.rawValue |
JPAuthorizationOptions.sound.rawValue |
JPAuthorizationOptions.providesAppNotificationSettings.rawValue)
let entity: JPUSHRegisterEntity = JPUSHRegisterEntity()
entity.types = Int(JPAuthorizationOptions.alert.rawValue |
JPAuthorizationOptions.badge.rawValue |
JPAuthorizationOptions.sound.rawValue |
JPAuthorizationOptions.providesAppNotificationSettings.rawValue)
JPUSHService.register(forRemoteNotificationConfig: entity, delegate: self)
// Required
// init Push
// notice: 2.1.5 版本的 SDK 新增的注册方法,改成可上报 IDFA,如果没有使用 IDFA 直接传 nil
......@@ -29,54 +27,53 @@ extension AppDelegate: JPUSHRegisterDelegate {
// channel:channel
// apsForProduction:isProduction
// advertisingIdentifier:advertisingId];
#if DEBUG
let isProduction = false
#elseif TESTENV
let isProduction = false
#else
let isProduction = true
#endif
#if DEBUG
let isProduction = false
#elseif TESTENV
let isProduction = false
#else
let isProduction = true
#endif
JPUSHService.setup(withOption: launchOptions,
appKey: YhConstant.Jpush.appKey,
channel: "appStore",
apsForProduction: isProduction)
}
// 系统获取Token
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let deviceTokenStr = deviceToken.map {String(format: "%02.2hhx", arguments: [$0]) }.joined()
let deviceTokenStr = deviceToken.map { String(format: "%02.2hhx", arguments: [$0]) }.joined()
print("deviceToken:\(deviceTokenStr)")
JPUSHService.registerDeviceToken(deviceToken)
YHLoginManager.shared.deviceTokenModel.deviceToken = deviceTokenStr
YHButlerServiceManager.shared.updateApnsToken(token: deviceToken)
}
// 获取token 失败
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { // 可选
print("did Fail To Register For Remote Notifications With Error: \(error)")
#if DEBUG
YHHUD.flash(message: error.localizedDescription)
#elseif TESTENV
YHHUD.flash(message: error.localizedDescription)
#else
#endif
#if DEBUG
YHHUD.flash(message: error.localizedDescription)
#elseif TESTENV
YHHUD.flash(message: error.localizedDescription)
#else
#endif
}
// 点推送进来执行这个方法
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
JPUSHService.handleRemoteNotification(userInfo)
completionHandler(UIBackgroundFetchResult.newData)
// 转换到消息tab
YHLoginManager.shared.needJumpToMsgTabFlag = true
DispatchQueue.main.asyncAfter(deadline: .now() + 0.25, execute: {
goToMessagePage()
})
}
// 后台进前台
func applicationWillEnterForeground(_ application: UIApplication) {
DispatchQueue.main.async {
......@@ -86,9 +83,8 @@ extension AppDelegate: JPUSHRegisterDelegate {
clearAllUnreadBadge()
YHOSSManager.share.getOSSID()
}
func jpushNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: ((Int) -> Void)) {
func jpushNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: (Int) -> Void) {
let userInfo = notification.request.content.userInfo
if notification.request.trigger is UNPushNotificationTrigger {
JPUSHService.handleRemoteNotification(userInfo)
......@@ -105,58 +101,63 @@ extension AppDelegate: JPUSHRegisterDelegate {
NotificationCenter.default.post(name: YhConstant.YhNotification.didRevMsgNotifiction, object: nil)
}
}
func jpushNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: (() -> Void)) {
func jpushNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: () -> Void) {
let userInfo = response.notification.request.content.userInfo
if response.notification.request.trigger is UNPushNotificationTrigger {
JPUSHService.handleRemoteNotification(userInfo)
}
// 系统要求执行这个方法
completionHandler()
// 转换到消息tab
YHLoginManager.shared.needJumpToMsgTabFlag = true
DispatchQueue.main.asyncAfter(deadline: .now() + 0.25, execute: {
goToMessagePage()
if let msgType = userInfo["msg_type"] as? Int, msgType == YHMessageType.article.rawValue {
let model = YHNewsModel()
let taskId = userInfo["task_id"] as? Int ?? 0
model.article_id = userInfo["article_id"] as? Int ?? 0
model.news_type = userInfo["news_type"] as? Int ?? 0
model.cover_img = userInfo["cover_img"] as? String ?? ""
model.url = userInfo["url"] as? String ?? ""
model.media_url = userInfo["media_url"] as? String ?? ""
model.media_transcode_url = userInfo["media_transcode_url"] as? String ?? ""
printLog("DDDDY: \(model.id)")
yh_newsList.enterDetail(model)
self.viewModel.readMessage(taskId: taskId) { _, _ in
if let msgType = userInfo["msg_type"] as? Int {
if msgType == YHMessageType.article.rawValue {
let model = YHNewsModel()
let taskId = userInfo["task_id"] as? Int ?? 0
model.article_id = userInfo["article_id"] as? Int ?? 0
model.news_type = userInfo["news_type"] as? Int ?? 0
model.cover_img = userInfo["cover_img"] as? String ?? ""
model.url = userInfo["url"] as? String ?? ""
model.media_url = userInfo["media_url"] as? String ?? ""
model.media_transcode_url = userInfo["media_transcode_url"] as? String ?? ""
printLog("DDDDY: \(model.id)")
yh_newsList.enterDetail(model)
self.viewModel.readMessage(taskId: taskId) { _, _ in
}
return
}
if msgType == YHMessageType.trip.rawValue {
if let url = userInfo["url"] as? String {
YHMessageDetailListVC.detailWithTripUrl(url)
}
return
}
}
})
}
func jpushNotificationCenter(_ center: UNUserNotificationCenter, openSettingsFor notification: UNNotification) {
}
func jpushNotificationAuthorization(_ status: JPAuthorizationStatus, withInfo info: [AnyHashable: Any]?) {
}
}
extension AppDelegate {
func handleAppleLoginUser() {
if #available(iOS 13.0, *) {
// 注意 存储用户标识信息需要使用钥匙串来存储 这里使用NSUserDefaults 做的简单示例
let userIdentifier = UserDefaults.standard.value(forKey: "appleID") as? String
if let userIdentifier = userIdentifier {
let appleIDProvider = ASAuthorizationAppleIDProvider()
let appleIDProvider = ASAuthorizationAppleIDProvider()
appleIDProvider.getCredentialState(forUserID: userIdentifier) {
credentialState, _ in
switch credentialState {
case .authorized:
// 授权状态有效
......@@ -177,7 +178,7 @@ extension AppDelegate {
}
}
}
private func clearAllUnreadBadge() {
DispatchQueue.main.async {
if #available(iOS 16.0, *) {
......
......@@ -51,6 +51,9 @@ class YHOrderTipsItemView: UIView {
} else if msg.type == YHMessageType.article.rawValue {
return "银河资讯"
} else if msg.type == YHMessageType.trip.rawValue {
return "礼品兑换提醒"
} else {
return "--"
......
......@@ -286,6 +286,19 @@ class YHMessageDetailListVC: YHBaseViewController {
}
}
}
static func detailWithTripUrl(_ itemUrl: String) {
if !itemUrl.isEmpty, let token = YHLoginManager.shared.userModel?.token, token.count > 5 {
var url = itemUrl + "&param=\(YHLoginManager.shared.h5Token)"
url = url + "&app_platform=ios" + "&app_version=" + UIDevice.appVersion()
printLog("UURL: \(url)")
let vc = YHH5WebViewVC()
vc.url = url
vc.isFullScreenFlag = true
vc.isNeedRefreshDataFlag = true
UIViewController.current?.navigationController?.pushViewController(vc)
}
}
}
extension YHMessageDetailListVC: UITableViewDelegate, UITableViewDataSource {
......@@ -329,34 +342,46 @@ extension YHMessageDetailListVC: UITableViewDelegate, UITableViewDataSource {
return
}
if self.type == YHMessageType.trip.rawValue {
Self.detailWithTripUrl(item.url)
return
}
printLog("redirectPage:\(item.redirectPage)")
if item.redirectPage == YHRedirectPage.serviceTab.rawValue { // 服务tab页
UIViewController.current?.navigationController?.popToRootViewController(animated: false)
goTabBarBy(tabType: .service)
return
} else if item.redirectPage == YHRedirectPage.lifeTab.rawValue { // 首页-生活tab
}
if item.redirectPage == YHRedirectPage.lifeTab.rawValue { // 首页-生活tab
UIViewController.current?.navigationController?.popToRootViewController(animated: false)
goTabBarBy(tabType: .home)
NotificationCenter.default.post(name: YhConstant.YhNotification.didJumpToHomePageLifeTabNotification, object: nil)
return
} else if item.redirectPage == YHRedirectPage.newsTab.rawValue { // 首页-资讯tab
}
if item.redirectPage == YHRedirectPage.newsTab.rawValue { // 首页-资讯tab
UIViewController.current?.navigationController?.popToRootViewController(animated: false)
goTabBarBy(tabType: .home)
NotificationCenter.default.post(name: YhConstant.YhNotification.didJumpToHomePageNewsTabNotification, object: nil)
return
} else {
}
if let orderId = Int(item.orderId) {
printLog("orderId: \(orderId)")
self.requestOrderStatus(orderId: orderId) {
status in
// status 1 申请阶段 2办证阶段 3续期阶段
self.handleRouter(message: item, stage: status) {
// 没有满足相应跳转条件默认跳转到服务页
UIViewController.current?.navigationController?.popToRootViewController(animated: false)
goTabBarBy(tabType: .service)
}
// 处理订单相关逻辑
if let orderId = Int(item.orderId) {
printLog("orderId: \(orderId)")
self.requestOrderStatus(orderId: orderId) {
status in
// status 1 申请阶段 2办证阶段 3续期阶段
self.handleRouter(message: item, stage: status) {
// 没有满足相应跳转条件默认跳转到服务页
UIViewController.current?.navigationController?.popToRootViewController(animated: false)
goTabBarBy(tabType: .service)
}
}
}
......
......@@ -269,7 +269,9 @@ class YHMessageListVC: YHBaseViewController {
}
}
emptyDataTipsView.isHidden = msgArr.count > 0
// 礼品兑换通知
self.msgArr.append(self.viewModel.msgList.trip)
self.emptyDataTipsView.isHidden = self.msgArr.count > 0
self.tableView.reloadData()
didRefreshYinHeManagerUnreadMsg()
}
......
......@@ -21,6 +21,7 @@ enum YHMessageType: Int {
case renewal = 8 // 身份续签
case business = 9 // 商务
case article = 10 // 资讯
case trip = 11 // 礼物
case yinheManager = 9527 // 银河管家
}
......@@ -77,6 +78,9 @@ class YHMessageInfoModel: SmartCodable {
} else if type == YHMessageType.article.rawValue {
return "银河资讯"
} else if type == YHMessageType.trip.rawValue {
return "礼品兑换提醒"
}
return ""
}
......@@ -93,6 +97,7 @@ class YHMsgListModel: SmartCodable {
var renewal: YHMessageInfoModel = YHMessageInfoModel()
var business: YHMessageInfoModel = YHMessageInfoModel()
var article: YHMessageInfoModel = YHMessageInfoModel()
var trip: YHMessageInfoModel = YHMessageInfoModel()
required init() {
self.information.type = YHMessageType.infoFill.rawValue
......@@ -105,10 +110,11 @@ class YHMsgListModel: SmartCodable {
self.renewal.type = YHMessageType.renewal.rawValue
self.business.type = YHMessageType.business.rawValue
self.article.type = YHMessageType.article.rawValue
self.trip.type = YHMessageType.trip.rawValue
}
enum CodingKeys: String, CodingKey {
case information, certificate, draft, signature, approval, renewal, business, article
case information, certificate, draft, signature, approval, renewal, business, article, trip
case dataSubmission = "data_submission"
case goToHK = "go_to_hk"
}
......
......@@ -70,6 +70,10 @@ class YHDetailMessageCell: UITableViewCell {
} else if type == YHMessageType.business.rawValue {
bottomBtn.setTitle("".local, for: .normal)
lineView.isHidden = true
} else if type == YHMessageType.trip.rawValue {
bottomBtn.setTitle("去查看".local, for: .normal)
}
var bottomBtnHeight = (type == YHMessageType.business.rawValue) ? 0.0 : 52.0
......
......@@ -69,6 +69,9 @@ class YHMessageSessionCell: UITableViewCell {
self.iconImgView.image = UIImage(named: "msg_icon_news")
self.iconContentView.backgroundColor = UIColor(hex: 0xF0F5FF)
} else if model.type == YHMessageType.trip.rawValue {
self.iconImgView.image = UIImage(named: "msg_icon_gift")
}
self.badgeLabel.isHidden = model.unreadCount <= 0
......
......@@ -45,6 +45,7 @@ class YHMsgViewModel: NSObject {
self.msgList.renewal.type = YHMessageType.renewal.rawValue
self.msgList.business.type = YHMessageType.business.rawValue
self.msgList.article.type = YHMessageType.article.rawValue
self.msgList.trip.type = YHMessageType.trip.rawValue
callBackBlock(true, nil)
} else {
let error: YHErrorModel = YHErrorModel(errorCode: Int32(json.code), errorMsg: json.msg)
......
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Frame@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "Frame@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment