0

アプリのローカル通知を毎日リマインダーに設定しました。アプリがバックグラウンドにあるときにうまく機能します。ただし、アプリが閉じている/実行されていない場合、ユーザーが通知で[起動]をタップすると、アプリはメイン画面を起動してからホーム画面に戻ります。

私はここで多くのコードソリューションを試しましたが、そのほとんどはこれらの線に沿ったものです。

- (BOOL)application:(UIApplication *)application 
  didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
    if (notification) {
        // handle your notification here.
    }
}

しかし、これをどこに置いても、アプリは起動しますが、黒に変わります。
これが私のコードです、誰かが私がここで何をすべきかを理解するのを手伝ってくれますか?アプリのビルドにDreamweaver/phonegapを使用しています。

//
//  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)applicationDidFinishLaunchingWithOptions:(UIApplication *)application
{   
{ 
     UILocalNotification *localNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
}


    [[UIApplication sharedApplication]
     registerForRemoteNotificationTypes:
     UIRemoteNotificationTypeBadge  |
     UIRemoteNotificationTypeAlert   |
     UIRemoteNotificationTypeSound];

    NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
    NSDictionary *appDefaults =[NSDictionary dictionaryWithObject:@"NO" forKey:@"enableNotifications"];
    [defaults registerDefaults:appDefaults];
    [defaults synchronize];   
    [ super applicationDidFinishLaunching:application ];
}
 - (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
}


-(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
     **/
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"enableNotifications"]) { 
    [[UIApplication sharedApplication] cancelAllLocalNotifications];
    [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
    NSCalendar *calender = [NSCalendar autoupdatingCurrentCalendar];
    NSDate *currentDate = [NSDate date];

    NSDateComponents *dateComponents = [calender components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit)
                                                   fromDate:currentDate];

    NSDateComponents *temp = [[NSDateComponents alloc]init];

    [temp setYear:[dateComponents year]];
    [temp setMonth:[dateComponents month]];
    [temp setDay:[dateComponents day]];
    [temp setHour: 9];
    [temp setMinute:00];

    NSDate *fireTime = [calender dateFromComponents:temp];
    [temp release];

    // set up the notifier 
    UILocalNotification *localNotification = [[UILocalNotification alloc]init];
    localNotification.fireDate = fireTime;
    localNotification.timeZone = [NSTimeZone defaultTimeZone];

    localNotification.alertBody = @"Don't Forget Your 365 Day Photo Challenge!";
    localNotification.alertAction = @"LAUNCH";

    localNotification.soundName = UILocalNotificationDefaultSoundName;

    localNotification.repeatInterval = NSMinuteCalendarUnit;
    localNotification.applicationIconBadgeNumber = 0;
    [[UIApplication sharedApplication]scheduleLocalNotification:localNotification];
    [localNotification release];
}
else {[[UIApplication sharedApplication] cancelAllLocalNotifications];}
    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)dealloc
{
    [ super dealloc ];
}

@end
4

2 に答える 2

0

ローカル通知の場合は、次のものを追加する必要があります。

- (void)applicationDidFinishLaunchingWithOptions:(UIApplication *)application
{ 
     UILocalNotification *localNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
}

- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
}
于 2012-08-29T05:16:25.470 に答える
-1

それが判明したとして...

クラッシュした理由はわかりませんが、この問題を抱えている他の誰かがこれに遭遇した場合、リリース用のビルド時に通知がアプリを起動します....ビルド/実行時に機能しないようですデバッグまたは別の状態。

したがって、実行するときに RELEASE を実行すると、問題なく動作するはずです!

于 2012-10-02T12:10:45.670 に答える