0

示例:- 我在最小化状态下生成了 4 个具有 4 种类型的本地通知。

下面的通知类型。

  1. 信息

  2. 好友请求

  3. 视频电话

  4. 音频通话

通知显示在通知中心。

现在..我点击了第二个通知,

  1. 我怎样才能获得点击了多少通知?

  2. 如何获得第二个通知正文警报文本(内容)?

此方法不适用于最小化状态

像whatsApp ..我需要根据通知类型进入特定屏幕。

- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type {
NSString *Notitype=@"";
if ([[payload.dictionaryPayload valueForKey:@"type"]isEqualToString:@"video"]) {
    Notitype=@"video";
}
else if ([[payload.dictionaryPayload valueForKey:@"type"]isEqualToString:@"friendRequest"]) {
     Notitype=@"friend Request";
}
else if([[payload.dictionaryPayload valueForKey:@"type"] isEqualToString:@"message"] )
{
    Notitype=@"message";
}
else{
    Notitype=@"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]];
4

1 回答 1

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,可能的用户不会对通知做出反应,而是点击应用程序图标打开应用程序。因此,如果是视频通话或任何紧急情况,则必须通过DidFinishLaunchingWithOptions

于 2017-07-26T12:10:43.017 回答