1

私のプロジェクトでは、プッシュ通知を介してイベントとオファーを表示したいのですが、問題は、イベントまたはオファーの両方を表示できないことです。プッシュ通知のメッセージを特定する方法はありますか。コードは次のとおりです。

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    NSString *message = nil;
    id alert = [userInfo objectForKey:@"alert"];

    if ([alert isKindOfClass:[NSString class]]) {
        message = alert;
    } else if ([alert isKindOfClass:[NSDictionary class]]) {
        message = [alert objectForKey:@"body"];
    }
    if (alert) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Title"
                                                            message:@"AThe message." delegate:self
                                                  cancelButtonTitle:@"button 1"
                                                  otherButtonTitles:@"button", nil];
        [alertView show];
    }

    NSString *contentsInfo = [userInfo objectForKey:@"contTag"];
    NSLog(@"Received contents info : %@", contentsInfo);

    NSString *nibName = [AppDelegate fetchNibWithViewControllerName:@"EventsViewController"];

    EventsViewController *evc = [[EventsViewController alloc] initWithNibName:nibName bundle:nil];

    evc.newEvent = YES;

    [self.navigationController pushViewController:evc animated:YES];

    [UIApplication sharedApplication].applicationIconBadgeNumber = [[[userInfo objectForKey:@"aps"] objectForKey: @"badgecount"] intValue];
}
4

1 に答える 1

3

alertは常に、NSDictionarybody と show-view の 2 つのキーを持つ です。前者の値は警告メッセージで、後者はBoolean(falseまたはtrue) です。の場合false、アラートの [表示] ボタンは表示されません。デフォルトでは、ユーザーがタップするとアプリケーションを起動する [表示] ボタンが表示されます。

ドキュメントを確認してください

ここで説明されているように、メッセージのタイプを識別するために、追加のフィールドを指定できます

例:

{
   "aps":{
      "badge":1,
      "alert":"This is my special message!",
      "mycustomvar1":"123456",
      "mycustomvar2":"some text",
      "myspecialtext":"This is the best!",
      "url":"http://www.mywebsite.com"
   }
}
于 2012-09-06T06:53:01.227 に答える