I am working on an app, and what my next goal is to set an alarm. To set an alarm, I will upload the values to an adress in order to achieve later a notification so that I can warn the user with turning on the alarm.
Unfortunatelly, I am both new to IOS and don't know much about playing with those web services. So I am getting confused while I'm searching those all stuff. I found out how to make data. So problem is about posting to url adress. Briefly, what I want to do is for now, upload a data to that adress with the JSON format.
Another issue is also, since it is an alarm controller, having multiple alarms. I mean, user don't have to just set an alarm or alarms at once. User can set an alarm right now, and tomorrow maybe s/he would like to set another alarm, even user want to delete! Well, honestly, before deleting I'll be glad if I can handle the problem with uploading right now. So, that uploading and dynamically changing the JSON content in the adress is another confusion for me.
I will glad with your further comments / suggestions. I will be too happy if you can also explain what you say, because I might not understand to be honest :).
Hope you can help me! Thanks !
Here what I came so far with tons of efforts! Please help me for further..
NSMutableDictionary *alarmDic = [[NSMutableDictionary alloc] initWithCapacity:4];
//for (int i = 0; i < [self.arrayOfAlarm count]; i++) {
NSLog(@"token: %@", self.token);
[alarmDic setObject:[NSNumber numberWithInteger:42] forKey:@"Token"];
NSLog(@"kur id: %lu", alarm.kurID);
[alarmDic setObject:[NSNumber numberWithInteger:alarm.kurID] forKey:@"CurrencyId"];
NSLog(@"not val: %f", alarm.kurAlis);
[alarmDic setObject:[NSNumber numberWithFloat:alarm.kurAlis] forKey:@"NotificationValue"];
NSLog(@"%ld", (long)alarm.kurTur);
[alarmDic setObject:[NSNumber numberWithInteger:alarm.kurTur] forKey:@"Type"];
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:alarmDic
options:NSJSONWritingPrettyPrinted
error:nil];
NSLog(@"%@", [[NSString alloc] initWithData:jsonData
encoding:NSUTF8StringEncoding]);
NSString *dataLength = [NSString stringWithFormat:@"%lu", (unsigned long)[jsonData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"http://api-dvzalt.azurewebsites.net/api/Notification/PostNotification"]];
[request setHTTPMethod:@"POST"];
[request setValue:dataLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:jsonData];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if(conn) {
NSLog(@"Connection Successful");
} else {
NSLog(@"Connection could not be made");
}
In the log windows,
requestReply: Connection Successful
However, nothing happening on the api, telling this as always.
The requested resource does not support http method 'GET'.