I'm encountering a crash in my iPad application when using Split View or Slide Over multitasking mode. The crash is occurring with the error message:
Crashing on exception: child view controller:<UIPageViewController: 0x155f84200> should have parent view controller:<MyApp.HomeViewController: 0x29e040800> but actual parent is:<MyAoo.HomeViewController: 0x12d2c5e00>
The issue seems to be related to incorrect parent view controller assignments when retrieving the top view controller using the window. I've tried to address this by saving the persistent identifier in UserDefaults and comparing it when retrieving the key window, but the problem persists.
Here's a snippet of the code I'm using to retrieve the key window:
`static func getKeyWindow(for role: UISceneSession.Role = .windowApplication) -> UIWindow? {
for scene in shared.connectedScenes {
guard scene.session.role == role else { continue }
if let savedIdentifier = UserDefaults.standard.string(forKey: "\(scene.session.persistentIdentifier)") {
debugPrint("#### saved identifier is \(savedIdentifier)")
if scene.session.persistentIdentifier == savedIdentifier {
return (scene as? UIWindowScene)?.windows.first { $0.isKeyWindow }
} else {
debugPrint("#### didn't match identifier")
}
} else {
return (scene as? UIWindowScene)?.windows.first { $0.isKeyWindow }
}
}
return nil
}`
It seems like the issue arises when the app is opened in a split view, as the persistent identifier changes but the app fails to differentiate between the different instances. Consequently, it takes the wrong Split View window and returns the wrong HomeViewController instance, leading to the crash.
How can I properly handle the retrieval of the top view controller to avoid this crash in multitasking mode on iPad? Any insights or suggestions would be greatly appreciated.
Thanks in advance!
Post
Replies
Boosts
Views
Activity
I'm developing an iOS app that supports in-app purchases and I'm using StoreKit2 for handling transactions. While purchase, promotion, and restore purchase functionalities are working fine, I'm facing an issue with offer code redemption.
When I present the offer code redemption sheet using:
``SKPaymentQueue.default().presentCodeRedemptionSheet()``
I am able to redeem the offer code in App Store sheet. It's showing success. But after offer code redeem SKPaymentTransactionObserver does not seem to receive any updates or notifications. Specifically, the paymentQueue(_:updatedTransactions:) method is not being called.
public func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction])
import StoreKit
`class YourClass: NSObject, SKPaymentTransactionObserver {
override init() {
super.init()
SKPaymentQueue.default().add(self)
}
deinit {
SKPaymentQueue.default().remove(self)
}
public func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
for transaction in transactions {
switch transaction.transactionState {
case .purchased:
print("Transaction Purchased")
SKPaymentQueue.default().finishTransaction(transaction)
case .failed:
print("Transaction Failed")
SKPaymentQueue.default().finishTransaction(transaction)
case .restored:
print("Transaction Restored")
SKPaymentQueue.default().finishTransaction(transaction)
case .deferred:
print("Transaction Deferred")
case .purchasing:
print("Transaction Purchasing")
@unknown default:
print("Unknown Transaction State")
}
}
}
}
`
So I am not able to update the UI and also not able to send the details to server.
Steps I’ve Taken:
Verified that the observer is added to the SKPaymentQueue in the initializer and removed in deinit.
Tested on a real device, not just the simulator.
Checked that the offer code is valid and properly set up in App Store Connect.
Verified that the latest version of Xcode is being used.
Questions:
Is there a known issue with offer code redemption in StoreKit2 that might cause the observer not to receive notifications?
Are there additional steps or configurations required to ensure that the transaction observer is notified about offer code redemptions?
Are there any common pitfalls or troubleshooting tips for dealing with this issue?
Any assistance or insights would be greatly appreciated!