APNS (iOS8 이전)

2020. 9. 7. 12:24개발자료/iOS


반응형

# 등록

UIApplication *appDelegate = [UIApplication sharedApplication];
[appDelegate registerForRemoteNotificationTypes:(UIRemoteNotificationTypeNewsstandContentAvailability
                                                 | UIRemoteNotificationTypeAlert
                                                 | UIRemoteNotificationTypeBadge
                                                 | UIRemoteNotificationTypeSound )];

 

# 등록 결과 처리

// APNS 등록 성공 시 호출
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
	// 문자열 토큰 생성
	NSString* strToken = [NSString stringWithFormat:@"%@",deviceToken];
    strToken = [strToken stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
    strToken = [strToken stringByReplacingOccurrencesOfString:@" " withString:@""];
    // 토큰 서버에 전달
    
}

// APIS 등록 실패 시 호출
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{
	// 오류 확인
}

 

# Background 수신

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
}

 

# Forground 수신

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
	UIApplicationState state = [application applicationState];
	// Forground 처리
    if (state == UIApplicationStateActive ) {
    }
    // Background 처리
    else {
    }
}

# 알림 On/Off 체크

// 알림 설정이 꺼져있는 경우 
if([UIApplication sharedApplication].enabledRemoteNotificationTypes == UIRemoteNotificationTypeNone) { 
	
} 
// 알림 설정이 켜져있는 경우. 
else { 
	
}
반응형