2017-07-26 35 views
0

示例: - 我已生成4個本地通知,其中4個類型處於最小化狀態。當應用程序最小化時獲取本地通知文本ios

下面的通知類型。

  1. 消息

  2. 朋友請求

  3. 視頻通話

  4. 音頻呼叫

通知在通知中心中。

Noow..I點擊了第二個通知,

  1. 我怎樣才能得到它的通知點擊數?

  2. 我如何獲得第二次通知正文提醒文本(內容)?

this mehod is not working for minimize state

例如WhatsApp。我需要根據通知類型去特定的屏幕上。

- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type { 
NSString *[email protected]""; 
if ([[payload.dictionaryPayload valueForKey:@"type"]isEqualToString:@"video"]) { 
    [email protected]"video"; 
} 
else if ([[payload.dictionaryPayload valueForKey:@"type"]isEqualToString:@"friendRequest"]) { 
    [email protected]"friend Request"; 
} 
else if([[payload.dictionaryPayload valueForKey:@"type"] isEqualToString:@"message"]) 
{ 
    [email protected]"message"; 
} 
else{ 
    [email protected]"audio"; 
} 

我創建UILocalNotification這樣的:

UILocalNotification *notification = [[UILocalNotification alloc]init]; 
notification.repeatInterval = NSDayCalendarUnit; 
[notification setAlertBody:Notitype]; 
[notification setFireDate:[NSDate dateWithTimeIntervalSinceNow:1]]; 
[notification setTimeZone:[NSTimeZone defaultTimeZone]]; 
[[UIApplication sharedApplication] setScheduledLocalNotifications:[NSArray arrayWithObject:notification]]; 
+0

處理您可以請顯示您的代碼,您如何設置您的本地通知 –

+0

我已更新的代碼。 @NhhleshBagdiya請檢查 –

回答

0

對於設置本地通知如下:

// Schedule the notification 
    UILocalNotification *notification = [[UILocalNotification alloc]init]; 
    notification.repeatInterval = NSDayCalendarUnit; 
    [notification setAlertBody:Notitype]; 
    [notification setFireDate:[NSDate dateWithTimeIntervalSinceNow:1]]; 
    [notification setTimeZone:[NSTimeZone defaultTimeZone]]; 

    //Create user info for local notification. 
    NSDictionary* dict = @{@"Type": @"message", @"ID": @"set your unique ID", @"body": notification.alertBody,}; 
    notification.userInfo = dict; 

    //You can Set Type as: message, friend Request, video call, Audio call. 

    [[UIApplication sharedApplication] setScheduledLocalNotifications:[NSArray arrayWithObject:notification]]; 

爲得到哪種類型的本地通知的是點擊比你可以使用didReceiveLocalNotification委託。

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { 
    //[super application:application didReceiveLocalNotification:notification]; // In most case, you don't need this line 

    //Get notification type 
    NSString *notificationType = [notification.userInfo valueForKey:@"Type"]; 
    //notificationType as: message, friend Request, video call, Audio call. 

    NSString *notificationBody = [notification.userInfo valueForKey:@"Notification_body"]; 

    UIApplicationState state = [application applicationState]; 
    if (state == UIApplicationStateActive) { 
     // Application in foreground when notification is delivered. 

     if ([notificationType isEqual:@"message"]) { 
      //Handle message 
     } else if ([notificationType isEqual:@"friend Request"]) { 
      //Handle friend Request 

     } else if ([notificationType isEqual:@"video call"]) { 
      //Handle video call 

     } else if ([notificationType isEqual:@"Audio call"]) { 
      //Handle Audio call 

     } 

    } else if (state == UIApplicationStateBackground) { 
     // Application was in the background when notification was delivered. 
     if ([notificationType isEqual:@"message"]) { 
      //Handle message 
     } else if ([notificationType isEqual:@"friend Request"]) { 
      //Handle friend Request 

     } else if ([notificationType isEqual:@"video call"]) { 
      //Handle video call 

     } else if ([notificationType isEqual:@"Audio call"]) { 
      //Handle Audio call 

     } 

    } else { 

    } 
} 

更新

還要檢查這個同樣的事情在DidFinishLaunchingWithOptions,可能的用戶不要通知反應,但挖掘在App圖標,打開應用程序。所以在視頻通話或任何緊急情況下,它必須通過DidFinishLaunchingWithOptions