对于我的远程推送通知,我在AppDelegate
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
dm=[DataManager sharedManager];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
dm.screenHight=[UIScreen mainScreen].bounds.size.height;
dm.screenWidth=[UIScreen mainScreen].bounds.size.width;
NSLog(@"^^^^^^^^^^^^^^ Screen hight ^^^^^^^^^^^^^ %i",dm.screenHight);
// for PAYPAL
[PayPalMobile initializeWithClientIdsForEnvironments:@{PayPalEnvironmentProduction : @"YOUR_CLIENT_ID_FOR_PRODUCTION",PayPalEnvironmentSandbox : @"AQhrXRAyHg6nuJCma6vkl1ZtxmWUynzuf2temitMSJEZf8n74p9iKAt6TgSf"}];
/// FOR PAYPAL
NSLog(@"%@",userInfo);
NSDictionary *dictionary=[userInfo objectForKey:@"jsonContent"];
dm.notificationDictionary=dictionary;
if ( application.applicationState == UIApplicationStateActive )
{
UIViewController *viewController1;
viewController1 = [[SplashViewController alloc] initWithNibName:@"SplashViewController" bundle:nil];
UINavigationController *aNavigationController=[[UINavigationController alloc] initWithRootViewController:viewController1];
self.navigationcontroller = aNavigationController ;
self.navigationcontroller.navigationBar.hidden=YES;
[self.window setRootViewController:self.navigationcontroller];
[self.window makeKeyAndVisible];
}
else
{
UIViewController *viewController1;
viewController1 = [[SplashViewController alloc] initWithNibName:@"SplashViewController" bundle:nil];
UINavigationController *aNavigationController=[[UINavigationController alloc] initWithRootViewController:viewController1];
self.navigationcontroller = aNavigationController ;
self.navigationcontroller.navigationBar.hidden=YES;
//[self.window addSubview:[self.navigationcontroller view]];
//[self.window setRootViewController:viewController1];
[self.window setRootViewController:self.navigationcontroller];
[self.window makeKeyAndVisible];
}
}
这很好用。但我的问题是,当应用程序处于活动状态时,它会在单击通知之前自动重定向到相关页面。但我希望将应用程序当前屏幕保持在forground状态,并且只有用户将通知重定向到相关性页面。我怎样才能做到这一点?请帮我。 感谢
答案 0 :(得分:1)
如果您的应用处于有效状态,您可以在UIAlertView中显示通知详细信息。用户将通过警报执行操作。但你不能指望这种状态下的通知。
UIApplicationState appState = [application applicationState];
if (appState == UIApplicationStateActive) {
NSString *cancelTitle = @"Close";
NSString *showTitle = @"Show";
NSString *message = [[userInfo valueForKey:@"aps"] valueForKey:@"alert"];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@“Your Title”
message:message
delegate:self
cancelButtonTitle:cancelTitle
otherButtonTitles:showTitle, nil];
[alertView show];
return;
}