I'm using PayPal MPL iOS lib. When ever I press the cancel button an alert message is displayed. How do I prevent UiAlert from coming up?

- 601
- 2
- 13
- 25
1 Answers
It appears as if the Paypal library itself is putting the alertview up. So unless there is something in the paypal library to disable that feature then you probably can't directly disable it. There might be a couple of workarounds, here are my thoughts:
Listen to the notifications when a new UIWindow is displayed via NSNotification center. The notifications are listed at the bottom of the document.
Heres another post that deals with listening to the notification.
Is there a notification on iOS if a UIAlertView is shown?
My thought is maybe you can catch when the alertview is being shown the you can undo it by calling makeKeyAndVisible on your AppDelegates window object
[[UIApplication sharedApplication].delegate.window makeKeyAndVisible];
The other thought that to me seems like a total hack so I'm not going to advocate for or justify is to use method swizzling. If you swizzled the [show] function of UIAlertView then you could inject a simple if statement to decide wether or not to call the real show method effectively deciding wether or not the alert is really shown or not. There may be unforeseen consequences going this route. If your not familiar with the technique NSHipster has a writeup http://nshipster.com/method-swizzling/. Before going this route I would consider how necessary disabling the alert really is.