-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ios): initialize appsflyer #8951
base: canary
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,6 +123,10 @@ jobs: | |
enableScripts: false | ||
- name: Cap sync | ||
run: yarn workspace @affine/ios cap sync | ||
- name: Write afdevkey | ||
working-directory: packages/frontend/apps/ios/App | ||
run: | | ||
echo "${{ env.APPSFLYER_DEV_KEY }}" | base64 --decode -o App/afdevkey.plist | ||
Comment on lines
+126
to
+129
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error checking and validation for the APPSFLYER_DEV_KEY environment variable. Consider: 1) Checking if env var exists before attempting decode, 2) Validating decoded content is valid plist format, 3) Adding conditional to skip if not configured. Example: if [ -n "$APPSFLYER_DEV_KEY" ]; then echo "$APPSFLYER_DEV_KEY" | base64 --decode > App/afdevkey.plist || exit 1; fi Spotted by Graphite Reviewer (based on CI logs) |
||
- name: Signing By Apple Developer ID | ||
uses: apple-actions/import-codesign-certs@v3 | ||
id: import-codesign-certs | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,5 @@ App/**/*.p8 | |
*.zip | ||
*.cer | ||
App/fastlane/report.xml | ||
|
||
afdevkey.plist |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,112 @@ | ||
import UIKit | ||
import Capacitor | ||
import AppsFlyerLib | ||
import AppTrackingTransparency | ||
|
||
@UIApplicationMain | ||
class AppDelegate: UIResponder, UIApplicationDelegate { | ||
class AppDelegate: UIResponder, UIApplicationDelegate, AppsFlyerLibDelegate, DeepLinkDelegate { | ||
func onConversionDataSuccess(_ conversionInfo: [AnyHashable : Any]) { | ||
print("onConversionDataSuccess: \(conversionInfo)") | ||
} | ||
|
||
func onConversionDataFail(_ error: any Error) { | ||
print("onConversionDataFail: \(error)") | ||
} | ||
|
||
|
||
var window: UIWindow? | ||
var window: UIWindow? | ||
var appFlyerReady = false | ||
|
||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | ||
// Override point for customization after application launch. | ||
return true | ||
} | ||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | ||
|
||
func applicationWillResignActive(_ application: UIApplication) { | ||
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. | ||
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. | ||
// Get AppsFlyer preferences from .plist file | ||
guard let propertiesPath = Bundle.main.path(forResource: "afdevkey", ofType: "plist"), | ||
let properties = NSDictionary(contentsOfFile: propertiesPath) as? [String:String] else { | ||
print("WARNING: Cannot find `afdevkey`") | ||
return true | ||
} | ||
guard let appsFlyerDevKey = properties["appsFlyerDevKey"], | ||
let appleAppID = properties["appleAppID"] else { | ||
print("WARNING: Cannot find `appsFlyerDevKey` or `appleAppID` key") | ||
return true | ||
} | ||
|
||
if appsFlyerDevKey.isEmpty || appleAppID.isEmpty { | ||
return true | ||
} | ||
|
||
self.appFlyerReady = true | ||
|
||
func applicationDidEnterBackground(_ application: UIApplication) { | ||
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. | ||
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. | ||
} | ||
AppsFlyerLib.shared().isDebug = true | ||
|
||
func applicationWillEnterForeground(_ application: UIApplication) { | ||
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. | ||
} | ||
AppsFlyerLib.shared().appsFlyerDevKey = appsFlyerDevKey | ||
AppsFlyerLib.shared().appleAppID = appleAppID | ||
|
||
func applicationDidBecomeActive(_ application: UIApplication) { | ||
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. | ||
} | ||
AppsFlyerLib.shared().waitForATTUserAuthorization(timeoutInterval: 60) | ||
|
||
AppsFlyerLib.shared().delegate = self | ||
AppsFlyerLib.shared().deepLinkDelegate = self | ||
|
||
print("Appflyer is ready") | ||
|
||
return true | ||
} | ||
|
||
func applicationWillTerminate(_ application: UIApplication) { | ||
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. | ||
} | ||
func applicationWillResignActive(_ application: UIApplication) { | ||
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. | ||
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. | ||
} | ||
|
||
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool { | ||
// Called when the app was launched with a url. Feel free to add additional processing here, | ||
// but if you want the App API to support tracking app url opens, make sure to keep this call | ||
return ApplicationDelegateProxy.shared.application(app, open: url, options: options) | ||
} | ||
func applicationDidEnterBackground(_ application: UIApplication) { | ||
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. | ||
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. | ||
} | ||
|
||
func applicationWillEnterForeground(_ application: UIApplication) { | ||
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. | ||
} | ||
|
||
func applicationDidBecomeActive(_ application: UIApplication) { | ||
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. | ||
|
||
// if self.appFlyerReady { | ||
// AppsFlyerLib.shared().start() | ||
// if #available(iOS 14, *) { | ||
// ATTrackingManager.requestTrackingAuthorization { (status) in | ||
// switch status { | ||
// case .denied: | ||
// print("AuthorizationStatus is denied") | ||
// case .notDetermined: | ||
// print("AuthorizationStatus is notDetermined") | ||
// case .restricted: | ||
// print("AuthorizationStatus is restricted") | ||
// case .authorized: | ||
// print("AuthorizationStatus is authorized") | ||
// @unknown default: | ||
// fatalError("Invalid authorization status") | ||
// } | ||
// } | ||
// } | ||
// } | ||
} | ||
|
||
func applicationWillTerminate(_ application: UIApplication) { | ||
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. | ||
} | ||
|
||
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool { | ||
// Called when the app was launched with an activity, including Universal Links. | ||
// Feel free to add additional processing here, but if you want the App API to support | ||
// tracking app url opens, make sure to keep this call | ||
return ApplicationDelegateProxy.shared.application(application, continue: userActivity, restorationHandler: restorationHandler) | ||
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool { | ||
// Called when the app was launched with a url. Feel free to add additional processing here, | ||
// but if you want the App API to support tracking app url opens, make sure to keep this call | ||
if self.appFlyerReady { | ||
AppsFlyerLib.shared().handleOpen(url, options: options) | ||
} | ||
return ApplicationDelegateProxy.shared.application(app, open: url, options: options) | ||
} | ||
|
||
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool { | ||
// Called when the app was launched with an activity, including Universal Links. | ||
// Feel free to add additional processing here, but if you want the App API to support | ||
// tracking app url opens, make sure to keep this call | ||
return ApplicationDelegateProxy.shared.application(application, continue: userActivity, restorationHandler: restorationHandler) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>appsFlyerDevKey</key> | ||
<string></string> | ||
<key>appleAppID</key> | ||
<string></string> | ||
</dict> | ||
</plist> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The path should be
afdevkey.plist
since theworking-directory
directive has already placed execution context in theApp
directory. The current pathApp/afdevkey.plist
will attempt to write to a non-existent nested directory.Spotted by Graphite Reviewer
Is this helpful? React 👍 or 👎 to let us know.