-
Notifications
You must be signed in to change notification settings - Fork 61
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
Alert views presented on wrong view controller #7
Comments
We'll fix this in the next release. In the meantime, there is a workaround. First, add LPMessageTemplates.h/m to your project. These files are available if you download the SDK from Help > Setup. You'll need to initialize these templates by calling [LPMessageTemplates sharedTemplates] before calling [Leanplum start]. Then, in LPMessageTemplates.m, add this method: + (UIViewController *)visibleViewController
{
UIViewController *root = [UIApplication sharedApplication].keyWindow.rootViewController;
if (root.presentedViewController) {
return root.presentedViewController;
}
return root;
} And replace both occurrences of: [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alert animated:YES completion:nil]; with: [[LPMessageTemplatesClass visibleViewController] presentViewController:alert animated:YES completion:nil]; |
Do you know when the next release will happen? We're trying to determine if we should put in this fix now or if we should wait. Also, when you say next release are you referring to a new SDK? |
I would say within a week. The fix was tested in different scenarios, but if you have time to test it in your app, that would make sure we covered your specific use case. |
Thanks for the update. We'll run tests in our app with the fix you recommended and will let you know how it turns out. |
Hi @afirst, I tried your workaround, and it almost works. However, sometimes we have multiple view controllers presented on the rootViewController, so the following works better for us for the visibleViewController method: + (UIViewController *)visibleViewController
{
UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
while (topController.presentedViewController) {
topController = topController.presentedViewController;
}
return topController;
} We are still testing to see if this works in all situations, but so far things are much improved. |
Glad you were able to test it and thanks for the feedback! We'll incorporate that change. |
Cleaning up the opened issues. |
Here is my situation:
Warning: Attempt to present <UIAlertController: 0x7fbffa67c180> on <ViewController: 0x7fbffa4536a0> whose view is not in the window hierarchy!
So, it seems like Leanplum is attempting to present the UIAlertView on the rootViewController, which is no longer visible, instead of the current view controller that is being displayed.
Additionally, if I change the message type from "Alert" to "Center popup" in Leanplum, then it appears as expected.
I'm happy to provide more information or a sample project if that would help.
The text was updated successfully, but these errors were encountered: