iOS9打开另一个应用程序urlSchemes首先会弹出确认alertView。如何按下取消按钮获取callBack。
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"app://"]];
答案 0 :(得分:0)
在执行操作之前使用此方法进行确认:
- (void)openAppAfterConfirmation
{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Open App?"
message:@"OK to open app, Cancel to "
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * _Nonnull action) {
//do the CANCEL stuff here
}];
UIAlertAction *confirm = [UIAlertAction actionWithTitle:@"Confirm"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * _Nonnull action) {
//do the CONFIRM stuff here
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"app://"]];
}];
[alert addAction:cancel];
[alert addAction:confirm];
[self presentViewController:alert animated:YES completion:nil];
}
答案 1 :(得分:0)
正如@Alan所指出的那样,以下UIApplicationDelegate
方法可用于确定openURL
UIAlertView
的统计数据:
applicationWillResignActive
applicationDidEnterBackground
is-processing-app-switching
将被调用我想基于NSUserDefaults
的“is-processing-app-switching”这样的标记可以在true
调用之前设置为openURL
,并且当它为真时{{1} }可用于确定用户是否选择取消。在applicationDidEnterBackground
中,标志应设置为false。这个解决方法对我来说似乎很难看,但是当你真的想要确定is-processing-app-switching
中构建的统计数据时,至少是可行的。
再次感谢海报自己找出解决方案。
答案 2 :(得分:0)
在进行呼叫时,要控制用户何时触摸“取消”或“呼叫”按钮,我正在使用CallKit框架中的CXCallObserver来检测呼叫更改。
还添加了一个观察者来捕获应用程序,该应用程序在从调用请求返回后变为活动状态。
- (void)viewDidLoad {
[super viewDidLoad];
CXCallObserver *callObserver = [[CXCallObserver alloc] init];
// If queue is nil, then callbacks will be performed on main queue
[callObserver setDelegate:self queue:nil];
// Don't forget to store reference to callObserver, to prevent it from being released
self.callObserver = callObserver;
// Add an observer on application become active and set a selector to perform
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleAppBecomeActive:)
name:UIApplicationDidBecomeActiveNotification
object :nil];
}
在这里,我们委托呼叫状态的更改。
#pragma mark - CXCallObserverDelegate Delegate
- (void)callObserver:(CXCallObserver *)callObserver callChanged:(CXCall *)call {
if (call.outgoing) {
// Set flag to true
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"on-going-call"];
}
}
handleAppBecomeActive
选择器在观察者对以下内容做出反应时执行:
UIApplicationDidBecomeActiveNotification
- (void)handleAppBecomeActive {
// Get flag
bool onGoingCall = [[NSUserDefaults standardUserDefaults] boolForKey:"on-goin-call"];
if (onGoingCall) {
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"on-going-call"];
// The user chose the Call action, do something
}
}
不太花哨,但可以帮助检测用户在调用方法时选择了什么动作:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://111111111"]];