From 53dff92edfc6493385dc43c69d2635609e3fc550 Mon Sep 17 00:00:00 2001 From: zeng Date: Wed, 30 Apr 2025 17:21:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A8=E9=80=81=E5=8A=9F=E8=83=BD=E5=BC=80?= =?UTF-8?q?=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MoviaBox.xcodeproj/project.pbxproj | 30 +++++ .../xcshareddata/swiftpm/Package.resolved | 119 +++++++++++++++++- MoviaBox/AppDelegate/AppDelegate+APNS.swift | 62 +++++++++ .../AppDelegate/AppDelegate+OpenApp.swift | 33 ----- MoviaBox/Base/Networking/API/SPApnsAPI.swift | 21 ++++ MoviaBox/MoviaBox.entitlements | 2 + MoviaBox/Source/GoogleService-Info.plist | 30 +++++ MoviaBox/Source/Info.plist | 6 +- 8 files changed, 265 insertions(+), 38 deletions(-) create mode 100644 MoviaBox/AppDelegate/AppDelegate+APNS.swift create mode 100644 MoviaBox/Base/Networking/API/SPApnsAPI.swift create mode 100644 MoviaBox/Source/GoogleService-Info.plist diff --git a/MoviaBox.xcodeproj/project.pbxproj b/MoviaBox.xcodeproj/project.pbxproj index 5b55041..90c0521 100644 --- a/MoviaBox.xcodeproj/project.pbxproj +++ b/MoviaBox.xcodeproj/project.pbxproj @@ -9,6 +9,9 @@ /* Begin PBXBuildFile section */ 1B384A992DC1CFE800F5B1A2 /* FacebookCore in Frameworks */ = {isa = PBXBuildFile; productRef = 1B384A982DC1CFE800F5B1A2 /* FacebookCore */; }; 1B384A9B2DC1CFE800F5B1A2 /* FacebookLogin in Frameworks */ = {isa = PBXBuildFile; productRef = 1B384A9A2DC1CFE800F5B1A2 /* FacebookLogin */; }; + 1BF22FD12DC2169B0082429A /* FirebaseAnalytics in Frameworks */ = {isa = PBXBuildFile; productRef = 1BF22FD02DC2169B0082429A /* FirebaseAnalytics */; }; + 1BF22FD32DC2169B0082429A /* FirebaseCore in Frameworks */ = {isa = PBXBuildFile; productRef = 1BF22FD22DC2169B0082429A /* FirebaseCore */; }; + 1BF22FD52DC2169B0082429A /* FirebaseMessaging in Frameworks */ = {isa = PBXBuildFile; productRef = 1BF22FD42DC2169B0082429A /* FirebaseMessaging */; }; 91D08C5AEAE459A3B8EA48C6 /* Pods_MoviaBox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A81436A54285C9EE97EEBC50 /* Pods_MoviaBox.framework */; }; /* End PBXBuildFile section */ @@ -47,8 +50,11 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 1BF22FD52DC2169B0082429A /* FirebaseMessaging in Frameworks */, 91D08C5AEAE459A3B8EA48C6 /* Pods_MoviaBox.framework in Frameworks */, + 1BF22FD32DC2169B0082429A /* FirebaseCore in Frameworks */, 1B384A992DC1CFE800F5B1A2 /* FacebookCore in Frameworks */, + 1BF22FD12DC2169B0082429A /* FirebaseAnalytics in Frameworks */, 1B384A9B2DC1CFE800F5B1A2 /* FacebookLogin in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -144,6 +150,7 @@ minimizedProjectReferenceProxies = 1; packageReferences = ( 1B384A972DC1CFE800F5B1A2 /* XCRemoteSwiftPackageReference "facebook-ios-sdk" */, + 1BF22FCF2DC2169B0082429A /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */, ); preferredProjectObjectVersion = 77; productRefGroup = 1DBC405A2DA4EDFC0093FCB0 /* Products */; @@ -461,6 +468,14 @@ minimumVersion = 14.1.0; }; }; + 1BF22FCF2DC2169B0082429A /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/firebase/firebase-ios-sdk"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 11.12.0; + }; + }; /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ @@ -474,6 +489,21 @@ package = 1B384A972DC1CFE800F5B1A2 /* XCRemoteSwiftPackageReference "facebook-ios-sdk" */; productName = FacebookLogin; }; + 1BF22FD02DC2169B0082429A /* FirebaseAnalytics */ = { + isa = XCSwiftPackageProductDependency; + package = 1BF22FCF2DC2169B0082429A /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */; + productName = FirebaseAnalytics; + }; + 1BF22FD22DC2169B0082429A /* FirebaseCore */ = { + isa = XCSwiftPackageProductDependency; + package = 1BF22FCF2DC2169B0082429A /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */; + productName = FirebaseCore; + }; + 1BF22FD42DC2169B0082429A /* FirebaseMessaging */ = { + isa = XCSwiftPackageProductDependency; + package = 1BF22FCF2DC2169B0082429A /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */; + productName = FirebaseMessaging; + }; /* End XCSwiftPackageProductDependency section */ }; rootObject = 1DBC40512DA4EDFC0093FCB0 /* Project object */; diff --git a/MoviaBox.xcworkspace/xcshareddata/swiftpm/Package.resolved b/MoviaBox.xcworkspace/xcshareddata/swiftpm/Package.resolved index 70800b1..c0978d8 100644 --- a/MoviaBox.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/MoviaBox.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,6 +1,24 @@ { - "originHash" : "ca3cf5f8f83d297b47d2cb0edff3e06f294951e2e06fa55cfc82831103499b2a", + "originHash" : "356668427da72005d8cb60963e877385296f1863605fc5a20d1f75f2cec3b22c", "pins" : [ + { + "identity" : "abseil-cpp-binary", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/abseil-cpp-binary.git", + "state" : { + "revision" : "bbe8b69694d7873315fd3a4ad41efe043e1c07c5", + "version" : "1.2024072200.0" + } + }, + { + "identity" : "app-check", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/app-check.git", + "state" : { + "revision" : "61b85103a1aeed8218f17c794687781505fbbef5", + "version" : "11.2.0" + } + }, { "identity" : "facebook-ios-sdk", "kind" : "remoteSourceControl", @@ -9,6 +27,105 @@ "revision" : "c19607d535864533523d1f437c84035e5fb101cf", "version" : "14.1.0" } + }, + { + "identity" : "firebase-ios-sdk", + "kind" : "remoteSourceControl", + "location" : "https://github.com/firebase/firebase-ios-sdk", + "state" : { + "revision" : "fbd463894af94d90eb4d6a4e54080459a8179519", + "version" : "11.12.0" + } + }, + { + "identity" : "googleappmeasurement", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/GoogleAppMeasurement.git", + "state" : { + "revision" : "f7460ea630bddf172115c28493ae8b3798d95ce3", + "version" : "11.12.0" + } + }, + { + "identity" : "googledatatransport", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/GoogleDataTransport.git", + "state" : { + "revision" : "617af071af9aa1d6a091d59a202910ac482128f9", + "version" : "10.1.0" + } + }, + { + "identity" : "googleutilities", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/GoogleUtilities.git", + "state" : { + "revision" : "53156c7ec267db846e6b64c9f4c4e31ba4cf75eb", + "version" : "8.0.2" + } + }, + { + "identity" : "grpc-binary", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/grpc-binary.git", + "state" : { + "revision" : "cc0001a0cf963aa40501d9c2b181e7fc9fd8ec71", + "version" : "1.69.0" + } + }, + { + "identity" : "gtm-session-fetcher", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/gtm-session-fetcher.git", + "state" : { + "revision" : "4d70340d55d7d07cc2fdf8e8125c4c126c1d5f35", + "version" : "4.4.0" + } + }, + { + "identity" : "interop-ios-for-google-sdks", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/interop-ios-for-google-sdks.git", + "state" : { + "revision" : "040d087ac2267d2ddd4cca36c757d1c6a05fdbfe", + "version" : "101.0.0" + } + }, + { + "identity" : "leveldb", + "kind" : "remoteSourceControl", + "location" : "https://github.com/firebase/leveldb.git", + "state" : { + "revision" : "a0bc79961d7be727d258d33d5a6b2f1023270ba1", + "version" : "1.22.5" + } + }, + { + "identity" : "nanopb", + "kind" : "remoteSourceControl", + "location" : "https://github.com/firebase/nanopb.git", + "state" : { + "revision" : "b7e1104502eca3a213b46303391ca4d3bc8ddec1", + "version" : "2.30910.0" + } + }, + { + "identity" : "promises", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/promises.git", + "state" : { + "revision" : "540318ecedd63d883069ae7f1ed811a2df00b6ac", + "version" : "2.4.0" + } + }, + { + "identity" : "swift-protobuf", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-protobuf.git", + "state" : { + "revision" : "d72aed98f8253ec1aa9ea1141e28150f408cf17f", + "version" : "1.29.0" + } } ], "version" : 3 diff --git a/MoviaBox/AppDelegate/AppDelegate+APNS.swift b/MoviaBox/AppDelegate/AppDelegate+APNS.swift new file mode 100644 index 0000000..a4cd17b --- /dev/null +++ b/MoviaBox/AppDelegate/AppDelegate+APNS.swift @@ -0,0 +1,62 @@ +// +// AppDelegate+APNS.swift +// MoviaBox +// +// Created by 佳尔 on 2025/4/30. +// + +import UIKit +import FirebaseMessaging +import FirebaseCore + +extension AppDelegate { + + func registerAPNS() { + FirebaseApp.configure() + Messaging.messaging().delegate = self + + let center = UNUserNotificationCenter.current() + center.delegate = self + + center.requestAuthorization(options: [.badge, .sound, .alert]) { grant, error in + if grant { +// SPRewardsAPI.requestUploadOpenNotify(completer: nil) + } + } + UIApplication.shared.registerForRemoteNotifications() + } +} + +extension AppDelegate: UNUserNotificationCenterDelegate { + + func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { + Messaging.messaging().apnsToken = deviceToken + } + ///APP处于前台是接收通知消息 + func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { + completionHandler([.badge, .alert]) + } + + ///点击通知消息进入app + func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { + completionHandler() + } + +} + +//MARK: -------------- MessagingDelegate -------------- +extension AppDelegate: MessagingDelegate { + + func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) { + if let token = fcmToken { + SPApnsAPI.requestUploadDeviceToken(token: token) + } + + let dataDict: [String: String] = ["token": fcmToken ?? ""] + NotificationCenter.default.post( + name: Notification.Name("FCMToken"), + object: nil, + userInfo: dataDict + ) + } +} diff --git a/MoviaBox/AppDelegate/AppDelegate+OpenApp.swift b/MoviaBox/AppDelegate/AppDelegate+OpenApp.swift index e95395d..2d52257 100644 --- a/MoviaBox/AppDelegate/AppDelegate+OpenApp.swift +++ b/MoviaBox/AppDelegate/AppDelegate+OpenApp.swift @@ -9,39 +9,6 @@ import UIKit import FacebookCore -extension AppDelegate { - - func registerAPNS() { - let center = UNUserNotificationCenter.current() - center.delegate = self - - center.requestAuthorization(options: [.badge, .sound, .alert]) { grant, error in - if grant { -// SPRewardsAPI.requestUploadOpenNotify(completer: nil) - } - } - UIApplication.shared.registerForRemoteNotifications() - } -} - -extension AppDelegate: UNUserNotificationCenterDelegate { - - func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { -// NIMSDK.shared().updateApnsToken(deviceToken) - } - ///APP处于前台是接收通知消息 -// func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { -// completionHandler([.badge]) -// } - - ///点击通知消息进入app - func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { - completionHandler() - } - -} - - extension SceneDelegate { ///URL打开APP diff --git a/MoviaBox/Base/Networking/API/SPApnsAPI.swift b/MoviaBox/Base/Networking/API/SPApnsAPI.swift new file mode 100644 index 0000000..828b065 --- /dev/null +++ b/MoviaBox/Base/Networking/API/SPApnsAPI.swift @@ -0,0 +1,21 @@ +// +// SPApnsAPI.swift +// MoviaBox +// +// Created by 佳尔 on 2025/4/30. +// + +import UIKit + +class SPApnsAPI: NSObject { + static func requestUploadDeviceToken(token: String) { + var param = SPNetworkParameters(path: "/customer/firebaseToken") + param.parameters = ["fcm_token": token] + param.isToast = false + + SPNetwork.request(parameters: param) { (response: SPNetworkResponse) in + + } + + } +} diff --git a/MoviaBox/MoviaBox.entitlements b/MoviaBox/MoviaBox.entitlements index d705386..c2078c8 100644 --- a/MoviaBox/MoviaBox.entitlements +++ b/MoviaBox/MoviaBox.entitlements @@ -2,6 +2,8 @@ + aps-environment + development com.apple.developer.applesignin Default diff --git a/MoviaBox/Source/GoogleService-Info.plist b/MoviaBox/Source/GoogleService-Info.plist new file mode 100644 index 0000000..75c241b --- /dev/null +++ b/MoviaBox/Source/GoogleService-Info.plist @@ -0,0 +1,30 @@ + + + + + API_KEY + AIzaSyAT78NBZpoE2kazUeiWOBKuQNczOEtPPbU + GCM_SENDER_ID + 157639867903 + PLIST_VERSION + 1 + BUNDLE_ID + com.thimratv.app + PROJECT_ID + movia-c4ef0 + STORAGE_BUCKET + movia-c4ef0.firebasestorage.app + IS_ADS_ENABLED + + IS_ANALYTICS_ENABLED + + IS_APPINVITE_ENABLED + + IS_GCM_ENABLED + + IS_SIGNIN_ENABLED + + GOOGLE_APP_ID + 1:157639867903:ios:63bd57e22b7c906450fbca + + \ No newline at end of file diff --git a/MoviaBox/Source/Info.plist b/MoviaBox/Source/Info.plist index 74dc46b..be2b431 100644 --- a/MoviaBox/Source/Info.plist +++ b/MoviaBox/Source/Info.plist @@ -16,16 +16,14 @@ - FacebookAdvertiserIDCollectionEnabled - FacebookAppID 1228062532660582 - FacebookAutoLogAppEventsEnabled - FacebookClientToken ecc9787c931b242fa912481c41b39bb6 FacebookDisplayName $(PRODUCT_NAME) + FirebaseAppDelegateProxyEnabled + ITSAppUsesNonExemptEncryption LSApplicationQueriesSchemes