Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- ㅂㅅ 같은 삼성 노트북
- Linux
- 크롬
- 유투브 광고 우회
- tomcat
- 클러스터링
- 사운드 설치
- 초미세먼지
- 갤럭시북 사운드카드 설치
- 내장모니터끄기
- 미세먼지
- IOS
- java
- 공기청정기
- 포켓몬고 플러스
- aws
- 마스크
- 미국은 또 시궁창
- OSX
- 노트북 모니터 끄기
- PM 2.5
- 코로나
- 광고없이 보기
- lb
- Docker
- ubuntu-server
- 로드밸런싱
- 포켓몬 고
- 앞으로 가기
- 포켓몬고
Archives
- Today
- Total
살며사랑하며
IOS PUSH & CUSTOM ALERT 본문
APNS를 쓰기위한 기본 설정
== 앱 델리게이트에 추가==
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
/*
// 어플리케이션 실행시 옵션사항 중 Push 서비스 관련 정보를 추출
NSDictionary *userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if(userInfo != nil)
{
[self application:application didFinishLaunchingWithOptions:userInfo];
}
*/
//-- Set Notification
#ifdef __IPHONE_8_0
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
#else
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
#endif
// Add registration for remote notifications
application.applicationIconBadgeNumber = 0;
return YES;
}
// 어플리케이션이 최초 실행될 때에 어플리케이션이 푸시서비스를 이용함을 알리고 허용할지를 물어보게 하고 사용자의 동의를 얻었을 경우 실행되는 메서드
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
/**
* 이 메서드가 호출되면 APNS에 디바이스 정보를 등록하고 64바이트의 문자열을 받아오게 된다.
*/
NSMutableString *deviceId = [NSMutableString string];
const unsigned char* ptr = (const unsigned char*) [deviceToken bytes];
for(int i = 0 ; i < 32 ; i++)
{
[deviceId appendFormat:@"%02x", ptr[i]];
}
// 여기서 추출된 deviceId를 서드파티 서비스의 서버로 전송하여 관리한다.
_strApns = deviceId;
NSLog(@"APNS Device Token: %@", _strApns);
}
// 푸시 메시지를 받았을 경우 호출되는 메서드
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
//UIView *topView = window.rootViewController.view;
[StringUtil customAlert:window.rootViewController.view title:@"PUSH" message:[[userInfo valueForKey:@"aps"] valueForKey:@"alert"]];
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSLog(@"Error in registration. Error: %@", error);
}
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
}
오호라
[StringUtil customAlert:window.rootViewController.view title:@"PUSH" message:[[userInfo valueForKey:@"aps"] valueForKey:@"alert"]];
를 이용해서 푸쉬를 추가했네요....
StringUtil은 스태틱 클래스 펑션입니다.
먼저 헤더를 보면 두개의 함수가 있는데 얼렛창 여는것 닫는것 해서 있네요
#import이제 클래스쪽을 볼께요@interface StringUtil : NSObject +(void)customAlert:(UIView*)view title:(NSString*)strTitle message:(NSString*)strMsg; +(void)closeAlert:(id)sender; @end
#import "StringUtil.h" #import
@implementation StringUtil UIView* alertView; +(void)closeAlert:(id)sender{ NSLOG(@"function : %s ", __FUNCTION__); alertView.hidden = TRUE; } +(void)customAlert:(UIView*)view title:(NSString*)strTitle message:(NSString*)strMsg { if(alertView != NULL){ [alertView removeFromSuperview]; }
CGSize size = view.frame.size; float x = 0.1, y=0.3; alertView=[[UIView alloc]initWithFrame:CGRectMake(0,0, size.width, size.height)]; [alertView setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.5]]; UIView* bgView=[[UIView alloc]initWithFrame:CGRectMake(size.width*x, size.height*y, size.width*(1-x*2), size.height*(1-y*2))]; [bgView setBackgroundColor:[StringUtil colorWithHexString:CONST_BG]]; bgView.layer.cornerRadius = 10; bgView.layer.masksToBounds = YES; UIView* bgBottomView=[[UIView alloc]initWithFrame:CGRectMake(0,bgView.frame.size.height-40,bgView.frame.size.width,40)]; [bgBottomView setBackgroundColor:[UIColor whiteColor]]; UIView* bgTopView=[[UIView alloc]initWithFrame:CGRectMake(0,0,bgView.frame.size.width,40)]; [bgTopView setBackgroundColor:[UIColor whiteColor]]; UILabel *titleBorder = [[UILabel alloc] initWithFrame:CGRectMake(0, 40, bgView.frame.size.width, 1)]; [titleBorder setBackgroundColor:[StringUtil colorWithHexString:CONST_BG_BORDER]]; [bgView addSubview:titleBorder]; UIButton *btnClose = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 80, 25)]; btnClose.layer.cornerRadius = 10; btnClose.layer.masksToBounds = YES; [btnClose setCenter:CGPointMake(bgBottomView.frame.size.width/2, bgBottomView.frame.size.height/2)]; btnClose.titleLabel.font = [UIFont systemFontOfSize:12.0]; [btnClose setBackgroundColor:[UIColor whiteColor]]; [btnClose setTitle:@"CLOSE" forState:UIControlStateNormal]; [btnClose setTitleColor:[StringUtil colorWithHexString:CONST_BG] forState:UIControlStateNormal]; [btnClose setTitle:@"CLOSE" forState:UIControlStateHighlighted]; [btnClose addTarget:self action:@selector(closeAlert:) forControlEvents:UIControlEventTouchUpInside]; [btnClose setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted]; [btnClose setBackgroundImage:[StringUtil imageWithColor:[StringUtil colorWithHexString:CONST_BG]] forState:UIControlStateHighlighted]; [[btnClose layer] setBorderWidth:2.0f]; [[btnClose layer] setBorderColor:[StringUtil colorWithHexString:CONST_BG].CGColor]; [bgBottomView addSubview:btnClose]; UILabel *viewActivityLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 20)]; [viewActivityLabel1 setCenter:CGPointMake(bgTopView.frame.size.width/2, bgTopView.frame.size.height/2)]; viewActivityLabel1.text = strTitle; [viewActivityLabel1 setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.0]]; viewActivityLabel1.font = [UIFont fontWithName:@"Helvetica" size:15]; viewActivityLabel1.textColor = [StringUtil colorWithHexString:CONST_BG]; viewActivityLabel1.textAlignment = NSTextAlignmentCenter; [bgTopView addSubview:viewActivityLabel1]; UILabel *viewActivityLabel2 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 60)]; viewActivityLabel2.text = strMsg; [viewActivityLabel2 setCenter:CGPointMake(bgView.frame.size.width/2, bgView.frame.size.height/2)]; [viewActivityLabel2 setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.0]]; viewActivityLabel2.font = [UIFont fontWithName:@"Helvetica" size:12]; viewActivityLabel2.textColor = [UIColor whiteColor]; viewActivityLabel2.textAlignment = NSTextAlignmentCenter; [bgView addSubview:viewActivityLabel2]; [bgView addSubview:bgTopView]; [bgView addSubview:bgBottomView]; [alertView addSubview:bgView]; [view addSubview:alertView];
네 이제 해당 StringUtil.h파일을 pch파일에 등록을 하시면 커스텀 알림창이 뜹니다...} @end