iOS click to push to jump to the details page
Agents that receive remote pushes on iOS 6 and earlier
- application: didReceiveRemoteNotification;
- application: didReceiveRemoteNotification official documentation If the app is running, the app calls this method to process incoming remote notifications. If the app is not running when a remote notification arrives, the method launches the app and provides the appropriate information in the launch options dictionary . The app does not call this method to handle that remote notification. Instead, your implementation of the application:willFinishLaunchingWithOptions: or application:didFinishLaunchingWithOptions: method needs to get the remote notification payload data and respond appropriately.
If the application is running, the application calls this method to handle incoming remote notifications. If the application is not running when the remote notification arrives, this method starts the application and provides the start information. Applications will not call this method to handle remote notifications. At this time, you can get the push information through the application:didFinishLaunchingWithOptions: method. Although it is before iOS 6, the usage range is NS_DEPRECATED_IOS(3_0, 10_0). It's just that there are better options after iOS 7, so this seems a bit tasteless. If you want to adapt to iOS 6 and before, you need to implement this
New proxies from iOS 7 (included) to iOS 10 (not included).
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
NSLog(@"[XGDemo] receive slient Notification");
NSLog(@"[XGDemo] userinfo %@", userInfo);
if (application.applicationState == UIApplicationStateActive) {
//
}else {
[self pushToVCWithNotificationInfo:userInfo];
}
completionHandler(UIBackgroundFetchResultNewData);
}
- application:didReceiveRemoteNotification:fetchCompletionHandler official documentation Use this method to process incoming remote notifications for your app. Unlike the application:didReceiveRemoteNotification:method, which is called only when your app is running in the foreground,the system calls this method when your app is running in the foreground or background. If your delegate implements both methods, the app object calls the application:didReceiveRemoteNotification:fetchCompletionHandler: method.
application:didReceiveRemoteNotification: Called only when the application is running in the foreground, and this method can be called in the foreground, background, or not started. If both proxy methods are implemented, the system will only call application:didReceiveRemoteNotification:fetchCompletionHandler: Because our application is only compatible with iOS 8 and above, so I will not implement it - (void)application: didReceiveRemoteNotification ; after all, there is an updated Proxy, it is simpler not to deal with the situation that the application is not started separately. Of course you can also use - application: didReceiveRemoteNotification;
New proxy for iOS 10 and above
First add in application:didFinishLaunchingWithOptions
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
#endif
Then implement the proxy- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler {
NSLog(@"[XGDemo] click notification");
//
UNNotificationRequest *request = response.notification.request;
//
UNNotificationContent *content = request.content;
//
NSDictionary *userInfo = content.userInfo;
[self pushToVCWithNotificationInfo:userInfo];
completionHandler();
}
- userNotificationCenter: willPresentNotification: withCompletionHandler; // App
Jump to details page
- (void)jumpWithNotificationInfo:(NSDictionary *)info {
//
if (!info) {
return;
}
//
NSString *type = info[@"type"];
// ,
UIViewController *topView;
topView = [self topViewController]; //
[topView.navigationController popToRootViewControllerAnimated:NO]; //
if ([type isEqualToString:@"commentpass"]) { //
self.mainVC.selectedIndex = 0; // ,
DiscoveryDetialViewController *VC = [[DiscoveryDetialViewController alloc] init];
UINavigationController *nav = self.mainVC.childViewControllers[0];
VC.hidesBottomBarWhenPushed = YES;
[nav pushViewController:VC animated:YES];
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.