1

내 응용 프로그램의 게임 플레이 동안 응용 프로그램 내 배너 알림을 표시 할 표시되지 내 여기UIApplication didReceiveRemoteNotification는 인앱 배너

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
{  
    if (application.applicationState == UIApplicationStateActive) 
    { 
     // Show Alert -> 
     // UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Did receive a Remote Notification", nil) 
     // message:[apsInfo objectForKey:@"alert"] 
     // delegate:self 
     // cancelButtonTitle:NSLocalizedString(@"OK", nil) 
     // otherButtonTitles:nil]; 
     // [alertView show]; 
     // [alertView release]; 

     // Show Banner Notification 
    } 
} 

UIAlertView 내가 달성하고자하는 것의 예이다 현재 :

http://i.stack.imgur.com/bFnmj.jpg

어떻게 내 응용 프로그램의 게임 중 응용 프로그램 내 배너 알림 재생 구현하는 것이?

+0

시도한 내용은 무엇입니까? 'UILabel'이라는 다중 줄이있는'UIView'는 제가 제안한 것입니다 – klcjr89

+0

[응용 프로그램의 활성 상태에서 배너 스타일로 원격 푸시 알림을 표시하는 방법?] (http://stackoverflow.com/questions/13601533/) how-to-show-remote-push-notification-as-a-banner-style-in-app-state-of-app) – klcjr89

+0

감사합니다. troop231. 그것은 나에게 좋았다. – Lasigal

답변

2
#define BANNER_HEIGHT 66.0  

    if (!showingNotification) { 
     showingNotification = YES; 

     // retrieve message from your actual notification here 
     NSString *message = @"Showing notification"; 

     UIToolbar *newmessageBannerView = [[UIToolbar alloc] initWithFrame:CGRectMake(0, -BANNER_HEIGHT, self.view.frame.size.width, BANNER_HEIGHT)]; 
     newmessageBannerView.translucent = YES; 

     newmessageBannerView.barStyle = UIBarStyleBlack; 
     newmessageBannerView.backgroundColor = [UIColor blackColor]; 

     UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10.0, 33.0, 16.0, 16.0)]; 
     imageView.image = [UIImage imageNamed:@"icon_72"]; 
     [newmessageBannerView addSubview:imageView]; 
     [self.view addSubview:newmessageBannerView]; 

     UILabel *bannerLabel = [[UILabel alloc] initWithFrame:CGRectMake(40.0, 30.0, 320.0, 22.0)]; 
     bannerLabel.textAlignment = NSTextAlignmentLeft; 
     bannerLabel.textColor = [UIColor whiteColor]; 
     bannerLabel.font = [UIFont systemFontOfSize:17.0]; 
     bannerLabel.text = message; 
     bannerLabel.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0]; 
     bannerLabel.adjustsFontSizeToFitWidth = YES; 
     [newmessageBannerView addSubview:bannerLabel]; 

     [UIView animateWithDuration:0.25 delay:0.1 options:UIViewAnimationOptionCurveLinear 
         animations:^{ 
          newmessageBannerView.frame = CGRectMake(0, 0, self.view.frame.size.width, BANNER_HEIGHT); 
         } 
         completion:^(BOOL finished) { 
          [UIView animateWithDuration:0.25 delay:2.0 options:UIViewAnimationOptionCurveLinear 
               animations:^{ 
                newmessageBannerView.frame = CGRectMake(0, -BANNER_HEIGHT, self.view.frame.size.width, BANNER_HEIGHT); 
               }completion:^(BOOL finished) { 
                [newmessageBannerView removeFromSuperview]; 
                showingNotification = NO; 
               }]; 
         }]; 
    } 
} 

테스트 iOS 6.0, 7.04, 7.1을 사용해보십시오.