问题描述
同事们!
如果应用程序关闭,则无法找到任何其他信息以正确捕获通知。 就我而言,当我收到通知时,我的代码只运行 1 个 VC,不能再执行任何操作。我怎么能延迟?我的意思是:第一个应用程序启动,然后我的通知将被发布。 我可以通过延迟和计时器来完成,但我正在努力把所有事情都做得清晰正确。
所以,我有
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
__block AppDelegate * blockSelf = self;
Nsstring * jsonStrPush = userInfo[@"data"];
NSDictionary *fullDic = [[FrequentRepeateFunc sharedInstance] nsstring_to_Dic:jsonStrPush];
NSInteger type = [fullDic[@"push_type"] integerValue];
NSLog(@"PUSH NUMBER %ld",type);
NSDictionary *dataPush = fullDic[@"data"];
NSDictionary *newDatanotification = dataPush [@"notification"];
if(nc != nil){
switch (type) {
它们与 swift 相同。
我有大约 50 个类似的案例
case 25: {
NSDictionary *dic = @{@"json": dataPush};
[[NSNotificationCenter defaultCenter] postNotificationName:@"pushFromMap" object:nil userInfo:dic];
}
break;
下一步我得到了带有 NC.Default.addobserver 的 Observer 类,它调用了一些方法,例如:
@objc func pushFromMap(_ notification: Notification) {
guard let dicData = notification.userInfo?["json"] as? [String: Any] else { return }
guard let name = dicData["user_name"] as? String else { return }
guard let gender = dicData["gender"] as? Int else { return }
let storyboard = UIStoryboard(name: "NewDesign",bundle: nil)
let navContr = UIApplication.shared.windows[0].rootViewController as! UINavigationController
let controller = storyboard.instantiateViewController(withIdentifier: "SameViewController") as! SameViewController
controller.prepareController(parent: navContr,eventId: "",forImage: gender == 1 ? .goodHe : .goodShe,text: name) {}
}
如何为等待或条件创建延迟以检查应用程序是否处于活动模式?如果应用程序处于活动状态或 1-2 分钟前处于活动状态,则此代码非常有效。但如果我关闭应用程序,此通知将毫无用处。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)