diff --git a/Veloria.xcodeproj/project.pbxproj b/Veloria.xcodeproj/project.pbxproj index 12f7732..d603a62 100644 --- a/Veloria.xcodeproj/project.pbxproj +++ b/Veloria.xcodeproj/project.pbxproj @@ -194,6 +194,11 @@ BFF5B23D2DF034420044227A /* VPFeedbackViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFF5B23C2DF034420044227A /* VPFeedbackViewController.swift */; }; BFF5B23F2DF0443B0044227A /* VPWebScriptModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFF5B23E2DF0443B0044227A /* VPWebScriptModel.swift */; }; BFF5B2412DF045BF0044227A /* VPRewardsAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFF5B2402DF045BF0044227A /* VPRewardsAPI.swift */; }; + BFF5B2442DF050260044227A /* FacebookCore in Frameworks */ = {isa = PBXBuildFile; productRef = BFF5B2432DF050260044227A /* FacebookCore */; }; + BFF5B2462DF050260044227A /* FacebookLogin in Frameworks */ = {isa = PBXBuildFile; productRef = BFF5B2452DF050260044227A /* FacebookLogin */; }; + BFF5B2482DF051D90044227A /* AppDelegate+Thirdparty.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFF5B2472DF051D90044227A /* AppDelegate+Thirdparty.swift */; }; + BFF5B24A2DF0524D0044227A /* AppDelegate+Open.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFF5B2492DF0524D0044227A /* AppDelegate+Open.swift */; }; + BFF5B24C2DF052E80044227A /* VPLoginManager+fb.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFF5B24B2DF052E80044227A /* VPLoginManager+fb.swift */; }; F939C04AD4003BA127F15C28 /* Pods_Veloria.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 34F57E87E765BF8D72A43DCA /* Pods_Veloria.framework */; }; /* End PBXBuildFile section */ @@ -395,6 +400,9 @@ BFF5B23C2DF034420044227A /* VPFeedbackViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VPFeedbackViewController.swift; sourceTree = ""; }; BFF5B23E2DF0443B0044227A /* VPWebScriptModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VPWebScriptModel.swift; sourceTree = ""; }; BFF5B2402DF045BF0044227A /* VPRewardsAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VPRewardsAPI.swift; sourceTree = ""; }; + BFF5B2472DF051D90044227A /* AppDelegate+Thirdparty.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AppDelegate+Thirdparty.swift"; sourceTree = ""; }; + BFF5B2492DF0524D0044227A /* AppDelegate+Open.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AppDelegate+Open.swift"; sourceTree = ""; }; + BFF5B24B2DF052E80044227A /* VPLoginManager+fb.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "VPLoginManager+fb.swift"; sourceTree = ""; }; E0BDA3570E00C90877E45AA0 /* Pods-VideoPlayer.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-VideoPlayer.debug.xcconfig"; path = "Target Support Files/Pods-VideoPlayer/Pods-VideoPlayer.debug.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -404,6 +412,8 @@ buildActionMask = 2147483647; files = ( F939C04AD4003BA127F15C28 /* Pods_Veloria.framework in Frameworks */, + BFF5B2442DF050260044227A /* FacebookCore in Frameworks */, + BFF5B2462DF050260044227A /* FacebookLogin in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -448,6 +458,8 @@ 1B056E212DDAC0FD007EE38D /* AppDelegate.swift */, 1B056E282DDAC0FD007EE38D /* SceneDelegate.swift */, BF0FA7312DDEBD6400C9E5F2 /* AppDelegate+Config.swift */, + BFF5B2472DF051D90044227A /* AppDelegate+Thirdparty.swift */, + BFF5B2492DF0524D0044227A /* AppDelegate+Open.swift */, ); path = AppDelegate; sourceTree = ""; @@ -674,6 +686,7 @@ children = ( BF0FA6D92DDC5CB600C9E5F2 /* VPLoginManager.swift */, BFF5B2242DEF02080044227A /* VPLoginManager+Apple.swift */, + BFF5B24B2DF052E80044227A /* VPLoginManager+fb.swift */, BF0FA6DB2DDC5CD700C9E5F2 /* VPTokenModel.swift */, BFF5B2262DEF022F0044227A /* VPThirdSignModel.swift */, ); @@ -1182,6 +1195,9 @@ ); mainGroup = 1B056DEB2DDABE2B007EE38D; minimizedProjectReferenceProxies = 1; + packageReferences = ( + BFF5B2422DF050260044227A /* XCRemoteSwiftPackageReference "facebook-ios-sdk" */, + ); preferredProjectObjectVersion = 77; productRefGroup = 1B056DF52DDABE2B007EE38D /* Products */; projectDirPath = ""; @@ -1291,6 +1307,7 @@ BF0FA74C2DDF060200C9E5F2 /* VPVideoPlayerViewController.swift in Sources */, BF0FA79B2DE1984B00C9E5F2 /* VPCollectListViewController.swift in Sources */, BF0FA7A32DE1AB1800C9E5F2 /* VPWatchHistoryCell.swift in Sources */, + BFF5B24C2DF052E80044227A /* VPLoginManager+fb.swift in Sources */, BF0FA76D2DE053C100C9E5F2 /* VPScrollView.swift in Sources */, BFF5B2202DEEE2C50044227A /* VPLoginContentView.swift in Sources */, 1B056E5D2DDACD8E007EE38D /* UIFont+VPAdd.swift in Sources */, @@ -1413,6 +1430,7 @@ BF0FA73F2DDEF26E00C9E5F2 /* VPHomeSearchButton.swift in Sources */, 1B056E512DDACBE5007EE38D /* VPViewController.swift in Sources */, BF0FA7122DDC6D2C00C9E5F2 /* VPHomeModuleItem.swift in Sources */, + BFF5B2482DF051D90044227A /* AppDelegate+Thirdparty.swift in Sources */, BFF5AFAC2DE70CE20044227A /* VPMeToolCell.swift in Sources */, BF5E75B32DE465EC00DE9DFE /* Dictionary+SPAdd.swift in Sources */, BF0FA7162DDC78FF00C9E5F2 /* ZKCycleScrollViewFlowLayout.swift in Sources */, @@ -1431,6 +1449,7 @@ 1B056E492DDAC3DF007EE38D /* VPAppTool.swift in Sources */, BFF5AFE62DEEDB7F0044227A /* VPRewardsViewController.swift in Sources */, BF0FA74E2DDF067E00C9E5F2 /* VPVideoPlayViewModel.swift in Sources */, + BFF5B24A2DF0524D0044227A /* AppDelegate+Open.swift in Sources */, BFF5B2412DF045BF0044227A /* VPRewardsAPI.swift in Sources */, BF0FA75B2DDF206000C9E5F2 /* VPExplorePlayerCell.swift in Sources */, BF0FA7412DDEFBC700C9E5F2 /* UIScrollView+VPRefresh.swift in Sources */, @@ -1683,6 +1702,30 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ + +/* Begin XCRemoteSwiftPackageReference section */ + BFF5B2422DF050260044227A /* XCRemoteSwiftPackageReference "facebook-ios-sdk" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/facebook/facebook-ios-sdk"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 14.1.0; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + BFF5B2432DF050260044227A /* FacebookCore */ = { + isa = XCSwiftPackageProductDependency; + package = BFF5B2422DF050260044227A /* XCRemoteSwiftPackageReference "facebook-ios-sdk" */; + productName = FacebookCore; + }; + BFF5B2452DF050260044227A /* FacebookLogin */ = { + isa = XCSwiftPackageProductDependency; + package = BFF5B2422DF050260044227A /* XCRemoteSwiftPackageReference "facebook-ios-sdk" */; + productName = FacebookLogin; + }; +/* End XCSwiftPackageProductDependency section */ }; rootObject = 1B056DEC2DDABE2B007EE38D /* Project object */; } diff --git a/Veloria.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Veloria.xcworkspace/xcshareddata/swiftpm/Package.resolved new file mode 100644 index 0000000..70800b1 --- /dev/null +++ b/Veloria.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -0,0 +1,15 @@ +{ + "originHash" : "ca3cf5f8f83d297b47d2cb0edff3e06f294951e2e06fa55cfc82831103499b2a", + "pins" : [ + { + "identity" : "facebook-ios-sdk", + "kind" : "remoteSourceControl", + "location" : "https://github.com/facebook/facebook-ios-sdk", + "state" : { + "revision" : "c19607d535864533523d1f437c84035e5fb101cf", + "version" : "14.1.0" + } + } + ], + "version" : 3 +} diff --git a/Veloria/AppDelegate/AppDelegate+Open.swift b/Veloria/AppDelegate/AppDelegate+Open.swift new file mode 100644 index 0000000..37b6e73 --- /dev/null +++ b/Veloria/AppDelegate/AppDelegate+Open.swift @@ -0,0 +1,29 @@ +// +// AppDelegate+Open.swift +// Veloria +// +// Created by 湖南秦九 on 2025/6/4. +// + +import UIKit +import FacebookCore + +extension SceneDelegate { + + func scene(_ scene: UIScene, openURLContexts URLContexts: Set) { + guard let url = URLContexts.first?.url else { + return + } + + //facebook + ApplicationDelegate.shared.application(UIApplication.shared, open: url, sourceApplication: nil, annotation: [UIApplication.OpenURLOptionsKey.annotation]) + + + } + + func scene(_ scene: UIScene, continue userActivity: NSUserActivity) { + guard let webpageURL = userActivity.webpageURL else { return } + + } + +} diff --git a/Veloria/AppDelegate/AppDelegate+Thirdparty.swift b/Veloria/AppDelegate/AppDelegate+Thirdparty.swift new file mode 100644 index 0000000..8696155 --- /dev/null +++ b/Veloria/AppDelegate/AppDelegate+Thirdparty.swift @@ -0,0 +1,19 @@ +// +// AppDelegate+Thirdparty.swift +// Veloria +// +// Created by 湖南秦九 on 2025/6/4. +// + +import UIKit +import FacebookCore + +extension AppDelegate { + + func registThirdparty(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) { + //facebook + ApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions) + + + } +} diff --git a/Veloria/AppDelegate/AppDelegate.swift b/Veloria/AppDelegate/AppDelegate.swift index 6aef8d6..2d9bb3c 100644 --- a/Veloria/AppDelegate/AppDelegate.swift +++ b/Veloria/AppDelegate/AppDelegate.swift @@ -21,6 +21,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate { VPLoginManager.manager.updateUserInfo(completer: nil) + self.registThirdparty(application, didFinishLaunchingWithOptions: launchOptions) + return true } diff --git a/Veloria/Class/Login/View/VPLoginContentView.swift b/Veloria/Class/Login/View/VPLoginContentView.swift index da6ffc2..804b305 100644 --- a/Veloria/Class/Login/View/VPLoginContentView.swift +++ b/Veloria/Class/Login/View/VPLoginContentView.swift @@ -61,7 +61,7 @@ class VPLoginContentView: HWPanModalContentView { }() private lazy var stackView: UIStackView = { - let stackView = UIStackView(arrangedSubviews: [appleButton]) + let stackView = UIStackView(arrangedSubviews: [facebookButton, appleButton]) stackView.axis = .vertical stackView.spacing = 20 return stackView @@ -75,6 +75,14 @@ class VPLoginContentView: HWPanModalContentView { return button }() + private lazy var facebookButton: VPLoginButton = { + let button = VPLoginButton() + button.icon = UIImage(named: "facebook_icon_01") + button.title = "Login with Facebook".localized + button.addTarget(self, action: #selector(handleFacebookButton), for: .touchUpInside) + return button + }() + override init(frame: CGRect) { super.init(frame: frame) @@ -147,6 +155,10 @@ extension VPLoginContentView { login(type: .apple) } + @objc private func handleFacebookButton() { + login(type: .faceBook) + } + private func login(type: VPLoginManager.LoginType) { VPHUD.show() VPLoginManager.manager.login(type: type, presentingViewController: nil) { [weak self] isFinish in diff --git a/Veloria/Libs/Login/VPLoginManager+fb.swift b/Veloria/Libs/Login/VPLoginManager+fb.swift new file mode 100644 index 0000000..e14e848 --- /dev/null +++ b/Veloria/Libs/Login/VPLoginManager+fb.swift @@ -0,0 +1,59 @@ +// +// VPLoginManager+fb.swift +// Veloria +// +// Created by 湖南秦九 on 2025/6/4. +// + +import UIKit +import FacebookLogin + +//https://developers.facebook.com/docs/facebook-login/ios?checkpoint_src=any +extension VPLoginManager { + + func facebookLogin(presentingViewController: UIViewController?, completer: ((_ model: VPThirdSignModel?) -> Void)?) { + + let loginManager = LoginManager() + loginManager.logOut() + loginManager.defaultAudience = .everyone + + loginManager.logIn(permissions: ["public_profile", "email"], from: presentingViewController) { result, error in + guard error == nil, let result = result else { + completer?(nil) + return + } + if result.isCancelled { + completer?(nil) + return + } + + let request = GraphRequest(graphPath: "me", parameters: ["fields" : "id,name,email,picture"], httpMethod: .get) + request.start { connection, result, error in + guard let result = result as? [String : Any] else { + completer?(nil) + return + } + let model = VPThirdSignModel() + model.platform = .faceBook + model.third_id = result["id"] as? String + model.email = result["email"] as? String + + if let picture = result["picture"] as? [String : Any], + let data = picture["data"] as? [String : Any], + let url = data["url"] as? String + { + model.avator = url + } + + if let name = result["name"] as? String { + model.family_name = name + } else { + model.family_name = result["first_name"] as? String + model.giving_name = result["last_name"] as? String + } + completer?(model) + } + + } + } +} diff --git a/Veloria/Libs/Login/VPLoginManager.swift b/Veloria/Libs/Login/VPLoginManager.swift index 83b6e83..df3b288 100644 --- a/Veloria/Libs/Login/VPLoginManager.swift +++ b/Veloria/Libs/Login/VPLoginManager.swift @@ -50,7 +50,13 @@ class VPLoginManager: NSObject { appleSignLogin { [weak self] model in self?.requestThirdLogin(thirdSignModel: model, completer: completer) } - default: break + + case .faceBook: + facebookLogin(presentingViewController: presentingViewController) { [weak self] model in + self?.requestThirdLogin(thirdSignModel: model, completer: completer) + } + default: + completer?(false) } } diff --git a/Veloria/Source/Assets.xcassets/icon/facebook_icon_01.imageset/Contents.json b/Veloria/Source/Assets.xcassets/icon/facebook_icon_01.imageset/Contents.json new file mode 100644 index 0000000..215149c --- /dev/null +++ b/Veloria/Source/Assets.xcassets/icon/facebook_icon_01.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "Facebook@2x.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "Facebook@3x.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Veloria/Source/Assets.xcassets/icon/facebook_icon_01.imageset/Facebook@2x.png b/Veloria/Source/Assets.xcassets/icon/facebook_icon_01.imageset/Facebook@2x.png new file mode 100644 index 0000000..ac933e4 Binary files /dev/null and b/Veloria/Source/Assets.xcassets/icon/facebook_icon_01.imageset/Facebook@2x.png differ diff --git a/Veloria/Source/Assets.xcassets/icon/facebook_icon_01.imageset/Facebook@3x.png b/Veloria/Source/Assets.xcassets/icon/facebook_icon_01.imageset/Facebook@3x.png new file mode 100644 index 0000000..f073917 Binary files /dev/null and b/Veloria/Source/Assets.xcassets/icon/facebook_icon_01.imageset/Facebook@3x.png differ diff --git a/Veloria/Source/Info.plist b/Veloria/Source/Info.plist index e5af543..94c2c3a 100644 --- a/Veloria/Source/Info.plist +++ b/Veloria/Source/Info.plist @@ -2,8 +2,32 @@ + CFBundleURLTypes + + + CFBundleTypeRole + Editor + CFBundleURLName + Facebook + CFBundleURLSchemes + + fb642299232204955 + + + + FacebookAppID + 642299232204955 + FacebookClientToken + b65496dbe4e9f22569d4438f693ae5a2 + FacebookDisplayName + $(PRODUCT_NAME) ITSAppUsesNonExemptEncryption + LSApplicationQueriesSchemes + + fbapi + fb-messenger-share-api + UIAppFonts PlayfairDisplay-VariableFont_wght.ttf diff --git a/Veloria/Source/en.lproj/Localizable.strings b/Veloria/Source/en.lproj/Localizable.strings index e7c32f6..0f0d85e 100644 --- a/Veloria/Source/en.lproj/Localizable.strings +++ b/Veloria/Source/en.lproj/Localizable.strings @@ -69,6 +69,7 @@ "Check in" = "Check in"; "Welcome to %@" = "Welcome to %@"; "Login with Apple" = "Login with Apple"; +"Login with Facebook" = "Login with Facebook"; "Log In" = "Log In"; "Sign Out" = "Sign Out"; "Delet Account" = "Delet Account"; diff --git a/Veloria/Veloria.entitlements b/Veloria/Veloria.entitlements index a812db5..d705386 100644 --- a/Veloria/Veloria.entitlements +++ b/Veloria/Veloria.entitlements @@ -6,5 +6,7 @@ Default + keychain-access-groups +