簡體   English   中英

退出或暫停應用程序時處理推送有效載荷

[英]Handle Push Payload when the App is Exited or Suspended

我已經處理了所有情況,但收到Push Payload的情況除外。

這是我的實現:

如果應用程序處於后台,非活動或活動狀態,則可以使用此方法接收通知。

-(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
       //Received Notification when the Application is Active, InActive or in Background State. 
       // NOTE : I am Handling below line of code with the Appropriate Conditions using Application States in my Code.
       [self handleNotificationDataWithDictionary:dictionary updateUI:YES];
}

如果應用程序被掛起或退出,那么我們可以通過didFinishLaunchingWithOptions方法接收通知有效載荷,但僅當用戶點擊通知時才可以。

這是通過從主屏幕或鎖定屏幕輕按推送通知退出或暫停和打開應用程序時接收有效負載的實現,

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
       if (launchOptions != nil)
       {
           NSDictionary *dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
           if (dictionary != nil)
           {
               [[[UIAlertView alloc] initWithTitle:@"Finish" message:@"Test" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil] show];
               NSLog(@"Launched from push notification: %@", dictionary);
              [self handleNotificationDataWithDictionary:dictionary updateUI:NO];
           }
       }
}

現在的最終情況是,當應用程序被掛起並且用戶沒有使用通知中心打開應用程序時,而是通過點擊應用程序圖標來打開應用程序。 在測試代​​碼時,在這種情況下我無法接收有效載荷。 我在Google上搜索了很多,但沒有找到解決方案。

根據應用程序文檔,當應用程序不活動時,我們只能在后台或不活動模式下獲得有效負載。 那么如何在暫停狀態下實施呢?

我確實需要幫助,請發布您的最佳答案,以便對他人也有用。

簡而言之- 如果用戶點擊“應用程序圖標”,您的推送就消失了 無法檢索該信息。

關於此的官方文檔:

如果在運行iOS的設備上輕按了應用程序圖標,則該應用程序調用相同的方法,但不提供有關通知的信息。

hris.to是絕對正確的,如果您想在應用程序中使用自定義通知面板,則必須構建一個API,然后再次從服務器獲取最新的通知。

暫無
暫無

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

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