0

I'm working with IOS app , and I'm facing a problem with uilocalnotification , my app working with web service ,

problems 1:

1 - my webService will return information such as date , time , days , and my app will add this date to local notification , the problem is web service return the days like this

Monday Tuesday Wednesday

and when i use UILocalNotification with dateComponent i found the dateComponent accept only one day and also the day must be int not string now how i can pass the day one this method

SetDay but not using int , using string like (Monday)

i have done this

 NSString * hour =@"23:00"; [dateComponent setWeekday:3]; // For Monday i want to change 3 with @"Monday" [dateComponent setHour:hour]; [dateComponent setMinute:minuts]; 

Problem 2 :

as we have seen setHour and SetMinute , i have only one string contain hour and Min is there any way to set both in one , because as you see I'm getting the time from string like above .

please help .

thanks

1 Answer 1

0

You could use something like this to get the day of the week as a number;

NSArray *dayNames = [[NSArray alloc] initWithObjects:@"Monday",@"Tuesday",@"Wednesday",@"Thursday",@"Friday",@"Saturday",@"Sunday",nil]; NSString *stringToFind = @"Thursday"; NSInteger dayOfWeek = [dayNames indexOfObject:stringToFind]; [dateComponent setWeekday:dayOfWeek]; 

Hope this helps.

Sign up to request clarification or add additional context in comments.

5 Comments

thanks but , also I'm asking if i want 1,2,3 how i can do it with setDay
Edited answer. If I understand your question correctly.
it's ok Dear , can you give me example .
I'm not sure I can at the moment. I think I've answered the part of your question that asked "how i can convert the days of week to integer and passed to dateComponent", but I'm not sure what else you need to know. Could you edit your question to be clearer?
So, to finish off for Problem 1 - I've answered that. If you want to set the day/weekday component, you have to provide an integer, so you need to convert your string, for example "Monday" to an integer using a method similar to what I have detailed in my answer above. For Problem 2, you will need to take your NSString, convert to a a NSDate, then you can extract the NSDateComponents and then set however you want, but each component has to be set separately, you can't set multiple components in one go, as far as I am aware. There is tons of stuff on NSDate conversion etc on SO so have a look.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.