2012-08-22 34 views
0

我想在我的iphone應用程序上創建本地通知。 我希望它每天早上9點發射一次。試圖讓本地通知在iphone應用程序中工作

但是沒有任何事情發生,無論是在模擬器或iPod上。

以下是我的appdelegate.m文件中xcode的完整代碼。
這個應用程序是使用phonegap在Dreamweaver中創建的......是一個問題? 我甚至在正確的地方有代碼嗎?

// 
// assignmentAppDelegate.m 
// assignment 
// 
// Created by Noel Chenier on 23 December, 2011. 
// Copyright 2011. All rights reserved. 
// 

#import "assignmentAppDelegate.h" 
#import "PhoneGapViewController.h" 

@implementation assignmentAppDelegate 


- (id) init 
{ 
    /** If you need to do any extra app-specific initialization, you can do it here 
    * -jm 
    **/ 
    return [super init]; 
} 

/** 
* This is main kick off after the app inits, the views and Settings are setup here. 
*/ 
- (void)applicationDidFinishLaunching:(UIApplication *)application 
{ 
    [ super applicationDidFinishLaunching:application ]; 
} 

-(id) getCommandInstance:(NSString*)className 
{ 
    /** You can catch your own commands here, if you wanted to extend the gap: protocol, or add your 
    * own app specific protocol to it. -jm 
    **/ 
    return [super getCommandInstance:className]; 
} 

/** 
Called when the webview finishes loading. This stops the activity view and closes the imageview 
*/ 
- (void)webViewDidFinishLoad:(UIWebView *)theWebView 
{ 
    return [ super webViewDidFinishLoad:theWebView ]; 
} 

- (void)webViewDidStartLoad:(UIWebView *)theWebView 
{ 
    return [ super webViewDidStartLoad:theWebView ]; 
} 

/** 
* Fail Loading With Error 
* Error - If the webpage failed to load display an error with the reson. 
*/ 
- (void)webView:(UIWebView *)theWebView didFailLoadWithError:(NSError *)error 
{ 
    return [ super webView:theWebView didFailLoadWithError:error ]; 
} 

/** 
* Start Loading Request 
* This is where most of the magic happens... We take the request(s) and process the response. 
* From here we can re direct links and other protocalls to different internal methods. 
*/ 
- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType 
{ 
    return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ]; 
} 


- (BOOL) execute:(InvokedUrlCommand*)command 
{ 
    return [ super execute:command]; 
} 


- (void)scheduleNotification{ 

    NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar]; 
    NSDate *today = [NSDate date]; 
    NSDateComponents *dateComponents = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit |NSMinuteCalendarUnit) fromDate:today]; 
    NSDateComponents *dateComps = [[NSDateComponents alloc] init]; 
    [dateComps setDay:dateComponents.day]; 
    [dateComps setMonth:dateComponents.month]; 
    [dateComps setYear:dateComponents.year]; 
    [dateComps setHour:9]; 
    [dateComps setMinute:00]; 
    NSDate *fireDate = [calendar dateFromComponents:dateComps]; 

    UILocalNotification *localNotif = [[UILocalNotification alloc] init]; 
    if (localNotif == nil) 
     return; 
    localNotif.fireDate = fireDate; 
    localNotif.timeZone = [NSTimeZone defaultTimeZone]; 
    localNotif.repeatInterval = NSMinuteCalendarUnit; 

    localNotif.alertBody = @"Don't forget your 365 Day Photo Challenge Assignment"; 
    localNotif.alertAction = @"LAUNCH"; 



    localNotif.soundName = UILocalNotificationDefaultSoundName; 
    localNotif.applicationIconBadgeNumber = 1; 

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif]; 
    [localNotif release]; 
} 


- (void)dealloc 
{ 
    [ super dealloc ]; 
} 

@end 

回答

0

我已經解決了。我在後面放置了代碼:

/** 
* This is main kick off after the app inits, the views and Settings are setup here. 
*/ 
- (void)applicationDidFinishLaunching:(UIApplication *)application 
{ 
相關問題