검색결과 리스트
Objective C에 해당되는 글 4건
- 2011.04.01 [iPhone] APNS 서버단 PHP 코드
- 2011.03.24 [iPhone]JSON 사용하기 (2)
- 2011.03.24 [iPhone]UIWebView에서 User-Agent 변경
- 2011.03.18 [C/C++]UDP Socket 예제 링크
글
먼저 키체인에서 해당 인증서를 이용해 .p12파일로 내보내기를 하여야 합니다.
PUSH인증서를 마우스 오른쪽 클릭하여 내보내기 합니다. (ex : cert.p12)
그리고 PUSH인증서에 물려있는 개인키 또한 내보내기 합니다. (ex : key.p12)
터미널을 열어서 2개의 파일이 있는 곳으로 이동하여 아래는 명령어를 입력합니다.
openssl pkcs12 -clcerts -nokeys -out cert.pem -in cert.p12
openssl pkcs12 -nocerts -out key.pem -in key.p12
openssl rsa -in key.pem -out key.unencrypted.pem
cat cert.pem key.unencrypted.pem > ck.pem
이렇게 하면 최종 산출물인 ck.pem 파일이 생성됩니다.
이 하나의 파일을 서버에 업로드 하면 됩니다.
아래는 서버단의 PHP소스 코드 입니다. 간단하게 인터넷에 널린 소스로 작성해 봤습니다.
<?php
$pass = 'C:\\APM_Setup\\htdocs\\ck.pem'; // 파일 경로
$token64 = '0fb09763c1278d20ec92045321501130fe16963728ecf98f3201b9c651e9a047'; // 테스트할 토큰..
// The actual notification payload
$body = array();
$body['aps'] = array('alert' => 'Message received from Bob');// 보낼 메세지
/* End of Configurable Items */
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', $pass);
$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
if (!$fp) {
echo "Failed to connect $err $errstr\n";
return;
}
$payload = json_encode($body);
// Thank you to the Perl example
$msg = chr(0).pack("n",32).pack('H*',$token64).pack("n",strlen($payload)).$payload;
fwrite($fp, $msg);
fclose($fp);
echo $err." bbbb<br/>";
echo $errstr." cccc";
?>
파일경로와 토큰만 제대로 써주시면 테스트하는데는 무리 없으리라 봅니다.
위와 같은 소스가 인터넷에 널려있는데.. 아무리 해도 안되길래..
$msg 쪽을 계속 바꿔봤더니 되더군요.. 소스마다 조금씩 틀리더군요..
그리고 php의 경우 openssl을 사용할 수 있도록 PHP에 설정을 해야합니다.
apmsetup의 경우 php확장 탭에 php_openssl.dll을 체크해주시고 restart 해주시면 됩니다.
리눅스 쪽은 찾아보진 않았지만 수정하면 되겠죵?ㅋ 참고하세요
'IT분야 > iOS' 카테고리의 다른 글
[iPhone]아이폰/아이패드 배포시 이미지 (0) | 2011.05.17 |
---|---|
[iPhone] UIWebView bounce 없애기 (0) | 2011.05.09 |
[iPhone] APNS 서버단 PHP 코드 (0) | 2011.04.01 |
[iPhone] 로그 남기기, Debug Release 구분하여 찍기 (0) | 2011.03.24 |
[iPhone] 네트워크 연결 상태 체크 (0) | 2011.03.24 |
[iPhone]JSON 사용하기 (2) | 2011.03.24 |
설정
트랙백
댓글
글
JSON을 사용하기 위해 Framework을 추가해서 하는 방법이 있던데.. 본인은 귀찮아서 헤더파일을 추가해서 씁니다.
http://stig.github.com/json-framework/ 에서 파일을 받고 압축을 풀러 classes안에 .h파일과 .m파일을
자신의 프로젝트에 복사하고 사용할때는 JSON.h 파일만 import 시키면 설정은 끝이다.
** 간단 사용법
---- SBJsonWriter ----
NSMutableDictionary *mdic= [[NSMutableDictionary alloc] init];
[mdic setValue: @"누구냐" forKey:@"deviceId"];
[mdic setValue: @"suroMind" forKey:@"token"];
[mdic setValue: @"한글" forKey:@"name"];
SBJsonWriter *writer=[[SBJsonWriter alloc]init];
NSString * params= [writer stringWithObject:mdic]; //JSON형태
[mdic release];
[writer release];
---- SBJsonParser ----
SBJsonParser *jsonParser = [[SBJsonParser alloc] init];
NSDictionary *dic = (NSDictionary*)[jsonParser
objectWithString:temp // 파싱할 NSString
error:&error];
NSString *tresultCode = [dic objectForKey:@"deviceId"];
NSString *type = [dic objectForKey:@"token"];
[jsonParser release];
'IT분야 > iOS' 카테고리의 다른 글
[iPhone] 로그 남기기, Debug Release 구분하여 찍기 (0) | 2011.03.24 |
---|---|
[iPhone] 네트워크 연결 상태 체크 (0) | 2011.03.24 |
[iPhone]JSON 사용하기 (2) | 2011.03.24 |
[iPhone]UIWebView에서 User-Agent 변경 (0) | 2011.03.24 |
[iPhone]Objective-C ~ Java AES 암호화 (6) | 2011.03.24 |
[iPhone] Xcode 개발툴 및 iPhone SDK 삭제 (0) | 2011.03.18 |
글
http://blog.suromind.com/94
위 링크에 새로운 방법이 제시 되어 있으니 확인해 보세요
=-=-====================================================================================================================
여러모로 삽질을 많이 한 부분입니다.
첫번째로 performselector를 이용하여 setCustomUserAgent 함수를 호출하고 수정하거나
두번째로
-(BOOL) webView:(UIWebView*) webView shouldStartLoadWithRequest:(NSURLRequest*) req navigationType:(UIWebViewNavigationType) navigationType
위 함수에서 헤더를 셋팅해주는 방법도 있다..
첫번째 방법은 비공개API라서 안된다하고 두번째 방법으로 해봤는데.. 되긴 되는데 잘 안된다.
JAVA 서블릿을 타면 헤더가 바뀔때도 있고 안바뀔때도 있고 지 멋대로다.. ㅜ
결국 찾은 방법은 외국사이트에서 찾았다.
================================= MethodSwizzling.h =================================
#import <Foundation/Foundation.h>
@interface NSObject (Swizzle)
+(BOOL)swizzleMethod:(SEL)origSelector withMethod:(SEL)newSelector;
@end
================================= MethodSwizzling.m ================================
#import "MethodSwizzling.h"
#import <objc/runtime.h>
@implementation NSObject (Swizzle)
+(BOOL)swizzleMethod:(SEL)origSelector withMethod:(SEL)newSelector{
Method origMethod = class_getInstanceMethod(self, origSelector);
Method newMethod = class_getInstanceMethod(self, newSelector);
if (origMethod && newMethod) {
if (class_addMethod(self, origSelector, method_getImplementation(newMethod), method_getTypeEncoding(newMethod))) {
class_replaceMethod(self, newSelector, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
} else {
method_exchangeImplementations(origMethod, newMethod);
}
return YES;
}
return NO;
}
@end
================================ MyMutableURLRequest.h ===========================
#import <Foundation/Foundation.h>
@interface NSMutableURLRequest (MyMutableURLRequest)
+ (void) setupUserAgentOverwrite;
@end
================================= MyMutableURLRequest.m ==========================
#import "MyMutableURLRequest.h"
#import "MethodSwizzling.h"
@implementation NSMutableURLRequest (MyMutableURLRequest)
- (void)newSetValue:(NSString *)value forHTTPHeaderField:(NSString *)field;
{
if ([field isEqualToString:@"User-Agent"]) {
if (![value hasPrefix:@"webview_iphone"]) {
value = [value stringByAppendingString:@",webview_iphone"];
}
//value = @"The new User-Agent string";
}
[self newSetValue:value forHTTPHeaderField:field];
}
+ (void)setupUserAgentOverwrite
{
[self swizzleMethod:@selector(setValue:forHTTPHeaderField:)
withMethod:@selector(newSetValue:forHTTPHeaderField:)];
}
@end
==========================================================================================
UserAgent값은 MyMutableURLRequest.m에서 value값을 통해 수정할 수 있다.
본인은 기본적으로 출력되는 값 뒤에 ,webview_iphone 을 stringByAppendingString 통해 추가하는
형식으로 집어넣었다. 이부분을 입맛에 맛게 수정하면 될듯 하다.
사용은 아래처럼 import해주고 뷰가 시작될때 한줄만 써주면 된다.
....
#import "MyMutableURLRequest.h"
....
-(void)viewDidLoad{
[super viewDidLoad];
[NSMutableURLRequest setupUserAgentOverwrite];
}
'IT분야 > iOS' 카테고리의 다른 글
[iPhone] 네트워크 연결 상태 체크 (0) | 2011.03.24 |
---|---|
[iPhone]JSON 사용하기 (2) | 2011.03.24 |
[iPhone]UIWebView에서 User-Agent 변경 (0) | 2011.03.24 |
[iPhone]Objective-C ~ Java AES 암호화 (6) | 2011.03.24 |
[iPhone] Xcode 개발툴 및 iPhone SDK 삭제 (0) | 2011.03.18 |
[iPhone] Lib Warning Finle not Found (0) | 2011.01.23 |
설정
트랙백
댓글
글
http://second27.egloos.com/4153083
http://namjja.egloos.com/5061861
http://second27.tistory.com/1
'IT분야 > C/C++' 카테고리의 다른 글
[C/C++]P2P UDP 네트워크 통신 자료 (0) | 2011.03.28 |
---|---|
[C/C++]네트워크 개발 관련 사이트 모음 - 펌 (0) | 2011.03.23 |
[C/C++]UDP Socket 예제 링크 (0) | 2011.03.18 |