I've an app and I am sending the parse norifications when the app is inActive and my code is like this? in my
我有一个应用程序,当应用程序处于活动状态时,我发送解析通知,我的代码是这样的?在我的
AppDelegate.m
-(void)application:(UIApplication *)app didReceiveRemoteNotification:(NSDictionary *)userInfo
{
if([app applicationState] == UIApplicationStateInactive)
{
//Here I've written
[PFPUSH handlePush:UserInfo];
}
}
But I need to go to a perticular page on this notification: For example I need to open my MUSICViewController on triggering the push notification. How to go that screen from app delegate; And another important thing is if the app is not launched, How I've to launch the app and handle the notification. And for info some data is to be get from server before the app launches. Please help how to handle it?
但是我需要在这个通知上找到一个特定的页面:例如,我需要在触发推送通知时打开我的MUSICViewController。如何从app delegate转到该屏幕;另一个重要的事情是,如果应用程序未启动,我将如何启动应用程序并处理通知。而对于信息,一些数据将在应用程序启动之前从服务器获取。请帮忙怎么处理?
2 个解决方案
#1
0
if you use storyboards
如果你使用故事板
UIViewController *controller = [[[[app keyWindow] rootViewController] storyboard] instantiateViewControllerWithIdentifier:@"MUSICViewController"];
else
MUSICViewController *viewController = [[MUSICViewController alloc] init];
than present this new VC
比现在这个新的VC
[[[app keyWindow] rootViewController] presentViewController:viewController
animated:YES
completion:nil];
if [[app keyWindow] rootViewController] is Navigation controller
if [[app keyWindow] rootViewController]是导航控制器
UIViewController *viewController = [[UIViewController alloc] init];
UINavigationController *nav = [[app keyWindow] rootViewController];
[nav pushViewController:nav animated:YES];
#2
0
i am sharing my application code might you get some idea from that
我正在分享我的应用程序代码,你可能会从中得到一些想法
- (void)applicationDidReceiveRemoteNotification:(NSDictionary *)userInfo fromState:(UIApplicationState)state
{
if ([UIApplication userId]) {
if (state == UIApplicationStateActive)
{
[[PPAlerts sharedAlerts]showAlertWithType:AlertTypeToast withMessage:[[userInfo valueForKey:@"aps"] valueForKey:@"alert"]];
//[PFPush handlePush:userInfo];
}
if (!IS_IPHONE_SIMULATOR)
{
if ([UIApplication userId])
{
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
if (currentInstallation.badge >= 1)
{
long k = currentInstallation.badge-1;
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:k];
currentInstallation.badge = k;
[currentInstallation saveInBackground];
}
}
}
if ([[userInfo objectForKey:@"t"] isEqualToString:@"request"] || [[userInfo objectForKey:@"t"] isEqualToString:@"t"]) {
self.isRequest = true;
}
else
{
self.isRequest = false;
}
NSLog(@"1-->user");
if ([UIApplication userId] && [[UIApplication sharedApplication] applicationState] != UIApplicationStateActive)
{
NSLog(@"2-->inactive");
if (self.sidePanelViewController==nil) {
NSLog(@"3-->forcestop");
LoginViewController *login= [[LoginViewController alloc]initWithNibName:@"LoginViewController" bundle:nil];
self.isNotifiction=true;
self.notificationID = [userInfo numberForJson:@"id"];
[self openMenuViewcontroller:login];
}
else
{
NSLog(@"4-->runnigBG");
if (self.isRequest) {
self.tabBarController.selectedIndex = 4;
}
else
{
NotificationViewController *notif=[[NotificationViewController alloc]initWithNibName:@"NotificationViewController" bundle:nil];
notif.isParseNotifiction=true;
self.notificationID = [userInfo numberForJson:@"id"];
SuperNavigationController *navNoti = [[SuperNavigationController alloc]initWithRootViewController:notif];
self.sidePanelViewController.centerPanel = navNoti;
}
}
}
else
{
// [[APIRequest request]HomeCount:@"0" completed:nil];
if (appDelegate.isLogin) {
[[APIRequest request]NotifictionCount:@"0" completed:nil];
[[APIRequest request]invitationCount:@"0" completed:nil];
[[APIRequest request]whislistCount:@"0" completed:nil];
}
NSLog(@"5-->active");
if(self.isRequest)
{
self.isRequest = false;
if (self.isRequestOpen) {
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
[[PFInstallation currentInstallation] setBadge:0];
[[PFInstallation currentInstallation] saveEventually];
}
}
else if (appDelegate.isNotifiction)
{
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
[[PFInstallation currentInstallation] setBadge:0];
[[PFInstallation currentInstallation] saveEventually];
[[APIRequest request]NotifictionAll:appDelegate.UserID ShowLoader:NO completed:nil];
}
else
{
}
}
}
}
#1
0
if you use storyboards
如果你使用故事板
UIViewController *controller = [[[[app keyWindow] rootViewController] storyboard] instantiateViewControllerWithIdentifier:@"MUSICViewController"];
else
MUSICViewController *viewController = [[MUSICViewController alloc] init];
than present this new VC
比现在这个新的VC
[[[app keyWindow] rootViewController] presentViewController:viewController
animated:YES
completion:nil];
if [[app keyWindow] rootViewController] is Navigation controller
if [[app keyWindow] rootViewController]是导航控制器
UIViewController *viewController = [[UIViewController alloc] init];
UINavigationController *nav = [[app keyWindow] rootViewController];
[nav pushViewController:nav animated:YES];
#2
0
i am sharing my application code might you get some idea from that
我正在分享我的应用程序代码,你可能会从中得到一些想法
- (void)applicationDidReceiveRemoteNotification:(NSDictionary *)userInfo fromState:(UIApplicationState)state
{
if ([UIApplication userId]) {
if (state == UIApplicationStateActive)
{
[[PPAlerts sharedAlerts]showAlertWithType:AlertTypeToast withMessage:[[userInfo valueForKey:@"aps"] valueForKey:@"alert"]];
//[PFPush handlePush:userInfo];
}
if (!IS_IPHONE_SIMULATOR)
{
if ([UIApplication userId])
{
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
if (currentInstallation.badge >= 1)
{
long k = currentInstallation.badge-1;
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:k];
currentInstallation.badge = k;
[currentInstallation saveInBackground];
}
}
}
if ([[userInfo objectForKey:@"t"] isEqualToString:@"request"] || [[userInfo objectForKey:@"t"] isEqualToString:@"t"]) {
self.isRequest = true;
}
else
{
self.isRequest = false;
}
NSLog(@"1-->user");
if ([UIApplication userId] && [[UIApplication sharedApplication] applicationState] != UIApplicationStateActive)
{
NSLog(@"2-->inactive");
if (self.sidePanelViewController==nil) {
NSLog(@"3-->forcestop");
LoginViewController *login= [[LoginViewController alloc]initWithNibName:@"LoginViewController" bundle:nil];
self.isNotifiction=true;
self.notificationID = [userInfo numberForJson:@"id"];
[self openMenuViewcontroller:login];
}
else
{
NSLog(@"4-->runnigBG");
if (self.isRequest) {
self.tabBarController.selectedIndex = 4;
}
else
{
NotificationViewController *notif=[[NotificationViewController alloc]initWithNibName:@"NotificationViewController" bundle:nil];
notif.isParseNotifiction=true;
self.notificationID = [userInfo numberForJson:@"id"];
SuperNavigationController *navNoti = [[SuperNavigationController alloc]initWithRootViewController:notif];
self.sidePanelViewController.centerPanel = navNoti;
}
}
}
else
{
// [[APIRequest request]HomeCount:@"0" completed:nil];
if (appDelegate.isLogin) {
[[APIRequest request]NotifictionCount:@"0" completed:nil];
[[APIRequest request]invitationCount:@"0" completed:nil];
[[APIRequest request]whislistCount:@"0" completed:nil];
}
NSLog(@"5-->active");
if(self.isRequest)
{
self.isRequest = false;
if (self.isRequestOpen) {
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
[[PFInstallation currentInstallation] setBadge:0];
[[PFInstallation currentInstallation] saveEventually];
}
}
else if (appDelegate.isNotifiction)
{
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
[[PFInstallation currentInstallation] setBadge:0];
[[PFInstallation currentInstallation] saveEventually];
[[APIRequest request]NotifictionAll:appDelegate.UserID ShowLoader:NO completed:nil];
}
else
{
}
}
}
}