簡體   English   中英

解析-當收到遠程通知IOS時,如何在打開應用程序(前景)時停止模式警報?

[英]Parse - How to stop modal alert while app opening(foreground), when received remote notification IOS?

在開發應用程序IOS時遇到問題,我使用了Parse Push Notification Framework進行推送遠程通知。 問題是當應用程序正在運行並且發送通知的同時,應用程序會自動顯示模式警報框。 因此,我不希望顯示模式警報。 我花了很多時間,並且在互聯網上進行了研究,閱讀了文檔,但沒有找到結果,我感到沒人知道這一點。 請幫我!

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

    // Override point for customization after application launch.

        UIImage *navBackgroundImage = [UIImage imageNamed:@"nav_bg_new"];

    [[UINavigationBar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];



    [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];

    // ****************************************************************************

    // Uncomment and fill in with your Parse credentials:

    // [Parse setApplicationId:@"your_application_id" clientKey:@"your_client_key"];

    // ****************************************************************************

    [Parse setApplicationId:@"my_app_id" clientKey:@"my_client_key"];

    // Override point for customization after application launch.

    [application registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound];





    return YES;

}


- (void)applicationWillResignActive:(UIApplication *)application

{

    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

}

- (void)applicationDidEnterBackground:(UIApplication *)application

{

    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 

    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

}

- (void)applicationWillEnterForeground:(UIApplication *)application

{

    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.

}



- (void)applicationDidBecomeActive:(UIApplication *)application

{

    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

}

- (void)applicationWillTerminate:(UIApplication *)application

{

    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

}



- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

    PFInstallation *currentInstallation = [PFInstallation currentInstallation];

    [currentInstallation setDeviceTokenFromData:deviceToken];

    currentInstallation.channels = @[@"global"];

    [currentInstallation saveInBackground];

}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {

    if (error.code == 3010) {

        NSLog(@"Push notifications are not supported in the iOS Simulator.");

    } else {

        // show some alert or otherwise handle the failure to register.      NSLog(@"application:didFailToRegisterForRemoteNotificationsWithError: %@", error);

    }

}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {    
    [PFPush handlePush:userInfo];

}

非常感謝。

如果僅要確保在打開應用程序時看不到通知,請在應用程序中將BOOL isOpening設置為TRUE application:willFinishLaunchingWithOptions:並在application:didFinishingLaunchingWithOptions:期間將其設置為FALSE,然后更改didReceiveRemoteNotification:和相應地調用PFPush handlePush:

您可以嘗試以下方法:

@property (nonatomic, assign) BOOL isLaunching;

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    isLaunching = TRUE;
}

- (void)applicationDidEnterForeground:(UIApplication *)application
{
    isLaunching = FALSE;
}

- (void)application:(UIApplication *)application    didReceiveRemoteNotification:(NSDictionary *)userInfo {
    if (!isLaunching) {
        //Only fire the push handler if the application isn't active
        [PFPush handlePush:userInfo];
    }
}

暫無
暫無

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

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