Cengiz
Cengiz

Reputation: 21

Linker error for app with in-app review and logging

As a Swift noob, I am getting the following linker error in Xcode when running my app:

ld: Undefined symbols:
  os.Logger.logObject.getter : __C.OS_os_log, referenced from:
      (1) suspend resume partial function for closure #1 @Sendable () async -> () in static godot_plugin.SwiftClass.launch_review_flow() -> () in InappReviewPlugin.a[4](SwiftClass.o)
      (3) suspend resume partial function for closure #1 @Sendable () async -> () in static godot_plugin.SwiftClass.launch_review_flow() -> () in InappReviewPlugin.a[4](SwiftClass.o)
  os.Logger.init() -> os.Logger, referenced from:
      one-time initialization function for logger in InappReviewPlugin.a[4](SwiftClass.o)
  type metadata accessor for os.Logger, referenced from:
      one-time initialization function for logger in InappReviewPlugin.a[4](SwiftClass.o)
      (1) suspend resume partial function for closure #1 @Sendable () async -> () in static godot_plugin.SwiftClass.launch_review_flow() -> () in InappReviewPlugin.a[4](SwiftClass.o)

The Swift code is trying to launch an in-app review form using StoreKit framework: [It is a part of an iOS in-app review plugin for Godot engine]

import Foundation
import SwiftUI
import OSLog
import StoreKit

@available(iOS 16.0, *)
extension UIApplication {
    class func getTopViewController(base: UIViewController? = UIApplication.shared.windows.first { $0.isKeyWindow }?.rootViewController) -> UIViewController? {
        if let nav = base as? UINavigationController {
            return getTopViewController(base: nav.visibleViewController)

        } else if let tab = base as? UITabBarController, let selected = tab.selectedViewController {
            return getTopViewController(base: selected)

        } else if let presented = base?.presentedViewController {
            return getTopViewController(base: presented)
        }
        return base
    }
}

@available(iOS 16.0, *)
extension UIViewController {
    /// Request a App Store review from the user
    /// 
    /// - Parameters:
    ///     - delay: The number of seconds this function will wait before showing the modal.
    func requestReview(delay: Double) {
        Task {
            // Use the equation n * 10^9 to convert seconds to nanoseconds.
            try? await Task.sleep(nanoseconds: UInt64(delay * pow(10.0, 9.0)))
            if let windowScene = self.view.window?.windowScene,
                self.navigationController?.topViewController == self {
                SKStoreReviewController.requestReview(in: windowScene)
            }
        }
    }
}

@available(iOS 16.0, *)
@objcMembers public class SwiftClass : NSObject
{
    static let logger = Logger()

    static func launch_review_flow() {
        Task {
            logger.info("SwiftClass: launch_review_flow(): Task")
            if let topVC = await UIApplication.getTopViewController() {
                logger.info("SwiftClass: launch_review_flow(): Task: topVC")
                await topVC.requestReview(delay: 1.5)
            }
        }
    }
}

I know it is related to the loggers and the partial functions around the await statements, but my attempts to fix this have failed.

Any help in fixing this problem would be appreciated.

Additionally, any suggestions on optimizing or correcting related or unrelated parts of the code would also be greatly appreciated.

Upvotes: 2

Views: 89

Answers (0)

Related Questions