程序返回前台调用方法

2017-11-04  本文已影响0人  elephant0001

做的一个需求是用户通过支付宝或者微信支付完成后,返回到我们的APP时  该支付页面发起支付结果判断的请求,我想到的解决办法是当用户支付完从支付宝或者微信返回APP时  APP从后台转换为前台。所以判断当用户从返回到前台是调用的特定的方法。

[[NSNotificationCenter defaultCenter] addObserver:self

selector:@selector(appHasGoneInForeground)

name:UIApplicationWillEnterForegroundNotification

object:nil];

-(void)appHasGoneInForeground{

[SVProgressHUD showWithStatus:@"订单查询中"];

isLoading = YES;

__block ErWeiMaViewController/*主控制器*/ *weakSelf = self;

dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0/*延迟执行时间*/ * NSEC_PER_SEC));

dispatch_after(delayTime, dispatch_get_main_queue(), ^{

[SVProgressHUD  dismiss];

[weakSelf delayMethod];

});

}

最后delayMethod  为自己想要做的操作

当然不要忘记在diddisappera 里面写上remove

-(void)viewDidDisappear:(BOOL)animated{

[[NSNotificationCenter defaultCenter] removeObserver:self];

[super viewDidDisappear:animated];

}

上一篇 下一篇

猜你喜欢

热点阅读