Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-20-2011, 03:37 PM   #1 (permalink)
Registered Member
 
Join Date: Jun 2011
Posts: 33
fast is on a distinguished road
Default Local notification date

hi,
I am creating an app that uses the local notification.
I am to see if they worked, I used a datapicker, but I would make sure that the date is decided by the code and not through the datapicker, so delete it.
here is my code right now:
Code:
	Class cls = NSClassFromString(@"UILocalNotification");
	if (cls != nil) {
		
		UILocalNotification *notif = [[cls alloc] init];
        
        notif.fireDate = [datePicker date];
		notif.timeZone = [NSTimeZone defaultTimeZone];
		notif.alertBody = @"Nuove previsioni Meteomar disponibili ora!";
		notif.soundName = @"harp.caf";
		//notif.applicationIconBadgeNumber = 1;
        notif.repeatInterval = NSDayCalendarUnit;	
		
		[[UIApplication sharedApplication] scheduleLocalNotification:notif];
		[notif release];
	}
Can you help me with the code?
fast is offline   Reply With Quote
Old 09-20-2011, 05:08 PM   #2 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

So what's the problem? If it doesn't fire, NSLog the date picker's date to see if it correct:
Code:
NSLog(@"The date from the UIDatePicker is:%@", [datePicker.date description]);
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 09-20-2011, 05:20 PM   #3 (permalink)
Registered Member
 
Join Date: Jun 2011
Posts: 33
fast is on a distinguished road
Default

No, you do not understand. I would delete the datapicker and manage the time of the notification code, I tried replacing it with this code, but should not be:
Code:
notif.fireDate = [06:00:00 date];
fast is offline   Reply With Quote
Old 09-20-2011, 07:30 PM   #4 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by fast View Post
No, you do not understand. I would delete the datapicker and manage the time of the notification code, I tried replacing it with this code, but should not be:
Code:
notif.fireDate = [06:00:00 date];
Of course that doesn't work. It's not legal code.

If you want to create a date from a constant value in your code, convert the date to a double with code like this

Code:
NSDate* pickerDate; 

//Get the date from your picker.
NSLog(@"Picker date in seconds is %d", 
 (int) [pickerDate timeIntervalSinceReferenceDate]);
Write down that value, and then add this code to your program:


Code:
Code:
notif.fireDate = 
  [NSDate dateWithTimeIntervalSinceReferenceDate: xxx];
[/quote] Where "xxx" is the number you get in the log statement above.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 09-22-2011, 10:35 AM   #5 (permalink)
Registered Member
 
Join Date: Jun 2011
Posts: 33
fast is on a distinguished road
Default

and if i write:
Code:
notif.fireDate = [NSDate dateWithTimeIntervalSinceReferenceDate:18];
fast is offline   Reply With Quote
Old 09-22-2011, 11:19 AM   #6 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by fast View Post
and if i write:
Code:
notif.fireDate = [NSDate dateWithTimeIntervalSinceReferenceDate:18];
Where did you get the number 18?

The method dateWithTimeIntervalSinceReferenceDate takes as input a number of seconds since midnight January 1, 2001. So that call woudl give you a date of 00:00:18 on January 1, 2001.

Somehow, I doubt if that's what you want.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 09-22-2011, 11:46 AM   #7 (permalink)
Registered Member
 
Join Date: Jun 2011
Posts: 33
fast is on a distinguished road
Default

I would for example set the alert to appear tomorrow night at 7PM.
how do I do?

Code:
NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *dateComps = [[NSDateComponents alloc] init];
    
    [dateComps setYear:2011];
    [dateComps setMonth:9];
    [dateComps setDay:22];
    
    [dateComps setHour:19];
    [dateComps setMinute:00];
    [dateComps setSecond:00];
    
    notif.fireDate = [calendar dateFromComponents:dateComps];
    notif.timeZone = [calendar timeZone];

Last edited by fast; 09-22-2011 at 12:07 PM.
fast is offline   Reply With Quote
Old 09-22-2011, 06:37 PM   #8 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by fast View Post
I would for example set the alert to appear tomorrow night at 7PM.
how do I do?

Code:
NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *dateComps = [[NSDateComponents alloc] init];
    
    [dateComps setYear:2011];
    [dateComps setMonth:9];
    [dateComps setDay:22];
    
    [dateComps setHour:19];
    [dateComps setMinute:00];
    [dateComps setSecond:00];
    
    notif.fireDate = [calendar dateFromComponents:dateComps];
    notif.timeZone = [calendar timeZone];
The code you posted should work perfectly.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 09-22-2011, 06:39 PM   #9 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

First get the current date using
Code:
NSDate *now = [NSDate date];
Then get the hour using NSCalendar's componentsFromDate method:
Code:
NSDate *now = [NSDate date];

NSCalendar *calendar = [NSCalendar currentCalendar];

NSDateComponents *currentHour = [calendar components:NSHourCalendarUnit fromDate:now];
Then find the difference between the hour and 7 pm
Code:
NSDate *now = [NSDate date];

NSCalendar *calendar = [NSCalendar currentCalendar];

NSDateComponents *currentHour = [calendar components:NSHourCalendarUnit fromDate:now];
int hour = [currentHour hour];
int offset = 19 - hour;
Then add a day and the offset using NSCalendar's dateByAddingComponents method:
Code:
NSDate *now = [NSDate date];

NSCalendar *calendar = [NSCalendar currentCalendar];

NSDateComponents *currentHour = [calendar components:NSHourCalendarUnit fromDate:now];
int hour = [currentHour hour];
int offset = 19 - hour;

NSDateComponents *timeToAdd = [NSDateComponents alloc] init];
[timeToAdd setDay: 1];
[timeToAdd setHour: offset];
NSDate *fireDate = [calendar dateByAddingComponents:timeToAdd toDate:now options:0];
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 09-22-2011, 07:11 PM   #10 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by Domele View Post
First get the current date using
Code:
NSDate *now = [NSDate date];
Then get the hour using NSCalendar's componentsFromDate method:
Code:
NSDate *now = [NSDate date];

NSCalendar *calendar = [NSCalendar currentCalendar];

NSDateComponents *currentHour = [calendar components:NSHourCalendarUnit fromDate:now];
Then find the difference between the hour and 7 pm
Code:
NSDate *now = [NSDate date];

NSCalendar *calendar = [NSCalendar currentCalendar];

NSDateComponents *currentHour = [calendar components:NSHourCalendarUnit fromDate:now];
int hour = [currentHour hour];
int offset = 19 - hour;
Then add a day and the offset using NSCalendar's dateByAddingComponents method:
Code:
NSDate *now = [NSDate date];

NSCalendar *calendar = [NSCalendar currentCalendar];

NSDateComponents *currentHour = [calendar components:NSHourCalendarUnit fromDate:now];
int hour = [currentHour hour];
int offset = 19 - hour;

NSDateComponents *timeToAdd = [NSDateComponents alloc] init];
[timeToAdd setDay: 1];
[timeToAdd setHour: offset];
NSDate *fireDate = [calendar dateByAddingComponents:timeToAdd toDate:now options:0];
Will that work if the current hour is before or after 19:00? I'm too tired to think it through completely.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 09-22-2011, 07:16 PM   #11 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Yes for example if it's 13:00, then the offset will be 6 hours. It'll had one day and 6 hours. If it's 21:00, then it'll add 22 hours (1 day - 2 hours).
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Reply

Bookmarks

Tags
local notifications, notifications

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 396
15 members and 381 guests
7twenty7, eski, EvilElf, fiftysixty, HemiMG, iOS.Lover, jarv, n00b, pbart, Pudding, sacha1996, Sami Gh, UMAD, VinceYuan, yuncarl28
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,672
Threads: 94,121
Posts: 402,905
Top Poster: BrianSlick (7,990)
Welcome to our newest member, yuncarl28
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:14 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0