gpt4 book ai didi

ios - 如何在 AppDelegate 的 didreceiveRemoteNotification 中处理远程推送通知

转载 作者:行者123 更新时间:2023-11-29 01:38:10 25 4
gpt4 key购买 nike

对于我的远程推送通知,我在我的 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];
}
}

这工作正常。但我的问题是当应用程序处于事件状态时,它会在单击通知之前自动重定向到相关页面。但我想保持应用程序当前屏幕,因为它在前台时以及只有用户点击时通知重定向到相关页面。我怎样才能做到这一点?请帮我。谢谢

最佳答案

如果您的应用处于事件状态,您可以在 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;
}

关于ios - 如何在 AppDelegate 的 didreceiveRemoteNotification 中处理远程推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32738653/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com