-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWebAppGatewayProtocol.m
150 lines (113 loc) · 3.85 KB
/
WebAppGatewayProtocol.m
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//
// WebAppGatewayProtocol.m
// ImIn
//
// Created by Myungjin Choi on 11. 10. 5..
// Copyright 2011년 KTH. All rights reserved.
//
#import "WebAppGatewayProtocol.h"
#import "NSString+URLEncoding.h"
@implementation WebAppGatewayProtocol
@synthesize delegate;
@synthesize whichVC, whichWebView;
// TODO: UI관련 공통 처리 모듈을 여기에 놓자
- (BOOL) processUiDescriptionWithData:(NSDictionary*) data
{
return YES;
}
// TODO: 앱내 호출 관련, 공통 처리 모듈을 여기 놓자
- (BOOL) processAppRequestWithData:(NSDictionary*) data
{
return YES;
}
- (BOOL) processWithUrl:(NSURL*) url
{
BOOL willContinue = NO;
NSDictionary* data = [self parseWithUrl:url];
if (self.delegate == nil) {
return YES;
}
if (data == nil) {
return YES;
}
if ([self.delegate respondsToSelector:@selector(willProcessUiDescriptionWithData:)]) {
willContinue = [self.delegate willProcessUiDescriptionWithData:data];
}
if (willContinue == NO) {
return NO;
}
willContinue = [self processUiDescriptionWithData:data];
if (willContinue == NO) {
return NO;
}
if ([self.delegate respondsToSelector:@selector(didProcessUiDescriptionWithData:)]) {
willContinue = [self.delegate didProcessUiDescriptionWithData:data];
}
if (willContinue == NO) {
return NO;
}
if ([self.delegate respondsToSelector:@selector(willProcessAppRequestWithData:)]) {
willContinue = [self.delegate willProcessAppRequestWithData:data];
}
if (willContinue == NO) {
return NO;
}
willContinue = [self processAppRequestWithData:data];
if (willContinue == NO) {
return NO;
}
if ([self.delegate respondsToSelector:@selector(didProcessAppRequestWithData:)]) {
willContinue = [self.delegate didProcessAppRequestWithData:data];
}
if (willContinue == NO) {
return NO;
}
return YES;
}
- (NSDictionary* ) parseWithUrl:(NSURL*) url
{
NSString* urlBody = [[[url absoluteString] componentsSeparatedByString:@"//"] lastObject];
urlBody = [urlBody URLDecodedString];
NSMutableDictionary *mutableDictionary = [[NSMutableDictionary alloc] init];
NSString* key = nil;
NSString* value = nil;
NSArray* keyValues;
[mutableDictionary setObject:url forKey:@"URL"];
if (urlBody == nil) {
[mutableDictionary setObject:@"error" forKey:@"schemename"]; //스키마이름 저장
return mutableDictionary;
}
NSArray* parts = [urlBody componentsSeparatedByString:@"?"];
if ([parts count] == 1) {
[mutableDictionary setObject:[parts objectAtIndex:0] forKey:@"schemename"];
keyValues = [[parts objectAtIndex:0] componentsSeparatedByString:@"/"];
} else if ([parts count] == 2) {
[mutableDictionary setObject:[parts objectAtIndex:0] forKey:@"schemename"];
keyValues = [[parts objectAtIndex:1] componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"=&"]];
}
for (int i=0; i < [keyValues count]; i++) {
if (i % 2 == 0) {
// key
key = [keyValues objectAtIndex:i];
} else {
// value
value = [keyValues objectAtIndex:i];
[mutableDictionary setObject:value forKey:key];
}
}
NSLog(@"mutableDictionary = %@", mutableDictionary);
return mutableDictionary;
}
#pragma mark - 아임IN 프로토콜
- (void) apiFailedWhichObject:(NSObject *)theObject {
}
- (void) closeVC {
if ([self.delegate respondsToSelector:@selector(closeVC)]) {
[self.delegate closeVC];
}
}
- (void) apiDidLoadWithResult:(NSDictionary *)result whichObject:(NSObject *)theObject {
if ([[result objectForKey:@"func"] isEqualToString:@"homeInfo"]) {
}
}
@end