colleagues!
Cant find any additional information for catching correctly notifications if app closed. In my case, when I receive notification, my code just running 1 VC, and can't do anything more. How I can place delay? I mean: first app launch, and after this my notification will be posted. I can do it with delay and timer, but im trying to do everything clear and correctly.
So, I've got
- (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) {
They are the same with swift.
and I've got about 50 cases like
case 25: {
NSDictionary *dic = @{@"json": dataPush};
[[NSNotificationCenter defaultCenter] postNotificationName:@"pushFromMap" object:nil userInfo:dic];
}
break;
Next step I got Observer class with NC.Default.addobserver which called some methods like:
@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) {}
}
How I can create delay for waiting or conditions to check if app in active mode? THis code works perfect if app is active, or was active 1-2 min ago. But if I close app, this notifications are useless.