'OSX'에 해당되는 글 4

  1. 2015.07.06 IOS PUSH & CUSTOM ALERT
  2. 2015.07.06 IOS 유니코드 변경
  3. 2015.07.06 IOS 루팅확인
  4. 2015.07.06 맥북 외장 모니터 연결시 내부 모니터 끄기 1

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];

}
 
@end
네 이제 해당 StringUtil.h파일을 pch파일에 등록을 하시면 커스텀 알림창이 뜹니다...


IOS 유니코드 변경

+(NSString *)urlEncodeValue:(NSString *)str{

str = 

[str stringByAddingPercentEscapesUsingEncoding:0x80000000 

kCFStringEncodingUnicode];

return 

(__bridge NSString *) CFURLCreateStringByAddingPercentEscapes(

kCFAllocatorDefault,

(__bridgeCFStringRef)str

,NULL,CFSTR("?=&+"),kCFStringEncodingUTF8);

 

}

IOS 루팅확인

+(BOOL) isRooting {

    NSString *filePath = @"/Applications/Cydia.app";

#if defined(__ROOTING_TRUE__)

    return TRUE;

#endif

    if ([[NSFileManager defaultManagerfileExistsAtPath:filePath]) return TRUE;

    else return FALSE;

}

맥북 외장 모니터 연결시 내부 모니터 끄기

여러가지 방법들이 있습니다.


1.맥북 화면 닫고 잠자기 깨운다음 화면 오픈...(라이온이상에서는 스크립트 수정해줘야 가능합니다.)

2. 오토메이터의 애플 스크립트를 이용하는 방법 (레티나에서는 안되는군요)

3. 유료 앱 사용하기

4. 무로 앱 사용하기


1,2,3번은 워낙 자료가 많습니다. 오늘 확인해본 결과 GitHub에 해당 프로젝트가 있네요.... 참고하시기 바랍니다.


GitHub 주소 : https://github.com/Eun/DisableMonitor


이 프로그램을 이용해서 사용하시면 됩니다. 다만 보안 및 개인정보의 손쉬운 사용해서 해당 앱의 컴퓨터 제어를 승인해야 합니다.

환경 > 보안및개인정보 > 개인정보 > 손쉬운사용


 

만드신분 - 누군지 몰라요
Eun/DisableMonitor
DisableMonitor - Easily disable or enable a monitor on your Mac.
github.com
본문으로 이동

해당 프로그램 설명화면