簡體   English   中英

如何在AppDelegate的didreceiveRemoteNotification中處理遠程推送通知

[英]How to handle Remote push notifications in didreceiveRemoteNotification in AppDelegate

對於我的遠程推送通知,我的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;
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM