-1

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'.
Kutay Demireren
  • 640
  • 1
  • 10
  • 25

1 Answers1

0

I guess you need an API,
your iPhone/iPad will send/request json to a route like "api/SetAlarm",
Heres a quick explanation,
also take a look at the accepted answer in another stackoverflow question Here.
Hope it helps

Community
  • 1
  • 1
BrunoMartinsPro
  • 1,646
  • 1
  • 24
  • 48
  • Thanks for the answer, first of all. I got an API already, friend on back-end did it. So web is ready and I just have to post there. – Kutay Demireren Jun 30 '15 at 16:56
  • Well I was looking the same before, but didn't make it work at all. Anyway, I will look it deeper now, thanks ! – Kutay Demireren Jun 30 '15 at 17:01
  • Can you please check my question again? I updated it. Took the same error as I looked up that link before. There must be something missing with me. – Kutay Demireren Jun 30 '15 at 17:12