-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.txt
More file actions
175 lines (135 loc) · 6.66 KB
/
README.txt
File metadata and controls
175 lines (135 loc) · 6.66 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
===============================================================================
Description
===============================================================================
This is the FeeFactor Objective-C Client Library - a helper library for
consuming FeeFactor Web Services. FeeFactor Web Services is used to access the
Netmobo platform which serves as a worry-free and cost-effective back office
for mobile applications.
===============================================================================
Introduction
===============================================================================
This library is geared for use in iOS applications.
To use the library, please sign up for a Netmobo account at
http://www.netmobo.com.
For assistance and more information, please email us at support@netmobo.com.
===============================================================================
Initial Steps for Using this Library in iOS applications
===============================================================================
With both your app project and the Netmobo source project open, do the
following:
1. Drag from the Netmobo source project Frameworks group the file 'libNetmobo.a'
to your project's Frameworks group and make sure 'copy' is selected from the
alert window.
2. Next, drag the grouping 'Netmobo' which contains the library's header files,
from the Netmobo source project to your project and make sure 'copy' is
selected from the alert window.
3. From the XCode menu, select 'Project' -> 'Edit Project Settings' and click
on the 'Build' tab
4. search for 'Header Search Paths' which is under 'Search Paths'
5. click '+' and double-click on 'path' and type in '/usr/include/libxml2'
6. search for 'other linker Flags' which is under 'linking'
7. click '+' and add '-lxml2'
Optionally, if you are having problems compiling, you may also add the ff to
'other link':
-ObjC
-all_load
===============================================================================
Authentication
===============================================================================
Create two UITextField IBOutlets to receive the user's username and password.
In this example, this is how we declared the IBOutlets:
//
// LoginViewController.h
// Reward
//
// Created by Netmobo on 8/20/10.
//
#import <UIKit/UIKit.h>
@interface LoginViewController : UIViewController <UITextFieldDelegate> {
UITextField *username;
UITextField *pw;
}
@property (nonatomic, retain) IBOutlet UITextField *username;
@property (nonatomic, retain) IBOutlet UITextField *pw;
- (IBAction) processLogin:(id) sender;
@end
Then in the implementation code, the username and password are passed to your
app's delegate to process the web service that will authenticate login. After
authentication, it will return an NSString variable. In this example, we store
the returned string in the variable 'errorCodeMsg'. errorCodeMsg will return
'none' if authentication was successful, otherwise, tell user in an error
message that there was something wrong with their login and that they could try
again:
- (IBAction) processLogin:(id) sender {
[self.pw resignFirstResponder];
NSString *usernameStr = [self.username text];
NSString *passwordStr = [self.pw text];
// user's username and password are passed to the
// delegate method 'loginWithUser: andPassword:'
RewardAppDelegate *mainDelegate = (RewardAppDelegate *)[[UIApplication
sharedApplication] delegate];
NSString *errorCodeMsg = [mainDelegate loginWithUser:usernameStr
andPassword:passwordStr];
// a singleton global variable called 'isLoggedIn' is used
// to keep track throughout the app that the user is logged in
Model *model = [Model sharedModel];
if ([errorCodeMsg isEqualToString:@"none"]) {
[model setIsLoggedIn:@"Y"];
// after setting global variable, let user into your app
// in this case, it goes to the pointHistory page which
// lists user's points history
[mainDelegate goPointHistory];
} else {
// if there is a problem with login (wrong username or password
// or unable to connect to web service, you can let your
// user try to log in again
[model setIsLoggedIn:@"N"];
UIAlertView *alert;
alert = [[UIAlertView alloc] initWithTitle:@"Login Error"
message:@"Wrong username or password" delegate:self
cancelButtonTitle:@"Try Again"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
Here is the code in the delegate that calls the Netmobo web service. First you
pass the Netmobo authentication fields along with the user's username and
password, with the username appended to the app's brandID. Note: there is no
need to modify the received user password, you can send it to the web service
as is. After authentication is successful, you will receive an errorCode with a
string value of "none" which this function returns. After successful web service
authentication, you may then retrieve needed user information for handling the
user's session such as userID, serialNumber, accountID:
- (NSString *) loginWithUser:(NSString *) aUser andPassword:(NSString *) aPassword {
Model *model = [Model sharedModel];
[transport3.config setSchema:@"http"];
[transport3.config setHost:@"api.feefactor.com"];
[transport3.config setPort:@"80"];
[transport3.config setServiceUrl:@"//rest"];
[transport3.config setUserName:[NSString stringWithFormat:@"%@|%@",
[model brandID], aUser] ];
[transport3.config setPassWord:aPassword];
[transport3.config setEncode:@"UTF-8"];
[transport3.config setRealm:@"feefactor"];
// after sending the necessary fields for authentication to the
// FeeFactor web service, you must execute a FeeFactor call to get
// a return error message describing successful authentication
// or not. In this case, we try to retrieve user info that
// will be used throughout the app. We call FeeFactor's
// accounts method: getAccounts: andSort: andPageItems: andPageNumber:
// method. During authentication, just pass an empty string
// to the fields 'getAccounts' and 'andSort' and the number 1
// to 'andPageItems' and 'andPageNumber'
Accounts *accountsInterface = [[Accounts alloc] init];
NSArray *accounts = [[accountsInterface getAccounts:@"" andSort:@""
andPageItems:[NSNumber numberWithInt:1] andPageNumber:[NSNumber
numberWithInt:1]] accountResults];
if ([transport3.config.errorCode isEqualToString:@"none"]) {
Account *account = [accounts objectAtIndex:0];
[model setUserID:[account.userID stringValue]];
[model setSerialNumber:[account.serialNumber stringValue]];
[model setAccountID:account.accountID];
}
return transport3.config.errorCode;
}