【问题标题】:How to handle Remote push notifications in didreceiveRemoteNotification in AppDelegate如何在 AppDelegate 中的 didreceiveRemoteNotification 中处理远程推送通知
【发布时间】:2015-09-23 11:43:20
【问题描述】:

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

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

【问题讨论】:

    标签: ios objective-c apple-push-notifications appdelegate


    【解决方案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;
        }
    

    【讨论】:

    • 按照 Apple 的建议,最好使用“UIAlertController”而不是“UIAlertView”。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多