3

を呼び出すアプリがありますが、 /var/mobile/ Applicationsではなく/ApplicationsscheduleLocalNotificationにインストールすると機能しません。

- (void) doNotify
{
    // this doesn't work when app is in /Applications but does in /var/mobile/Applications
    UILocalNotification * theNotification = [[UILocalNotification alloc] init];
    theNotification.alertBody = @"Finished processing.";
    theNotification.alertAction = @"Ok";
    theNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:1];
    [[UIApplication sharedApplication] scheduleLocalNotification:theNotification];
    NSLog(@"notification scheduled: %@", theNotification);
}

presentLocalNotificationタイミングの問題だった場合に備えて、代わりに試しました。

アプリデリゲートに実装didReceiveLocalNotificationして、代わりに呼び出されているかどうかを確認しましたが、そうではありませんでした。アプリがフォアグラウンドにあるときにのみ呼び出されました。

アプリを/var/mobile/Applicationsに戻すと、正常に動作します。Xcode 4.2.1 を使用し、iPhone 4S および iPod Touch 4g で iOS 5.1.1 を実行しています。

編集:音楽アプリなので、アプリはバックグラウンドで実行できます

4

2 に答える 2

0

ちょうど今同じ問題に遭遇しました。そして、私はすでに公式文書を通じてこの問題を解決しています。

実際、通知を使用するには、通知を登録する必要があります。

UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes: UIUserNotificationTypeAlert | UIUserNotificationTypeBadge categories:nil];
[[UIApplication shareApplication] registerUserNotificationSettings: settings];
于 2016-04-07T03:05:43.743 に答える
0

通知登録

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){

    [application registerUserNotificationSettings:[UIUserNotificationSettings
                                                   settingsForTypes:UIUserNotificationTypeAlert|  UIUserNotificationTypeSound | UIUserNotificationTypeBadge categories:nil]];
    }
    [launchOptions valueForKey:UIApplicationLaunchOptionsLocalNotificationKey];
}

スケジュール通知

- (void)applicationDidEnterBackground:(UIApplication *)application
 {
  // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.


    NSLog(@"startLocalNotification");
    UILocalNotification *notification = [[UILocalNotification alloc] init];
    notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:2];
    notification.alertBody = @"notification Message ";

    notification.timeZone = [NSTimeZone defaultTimeZone];
    notification.soundName = UILocalNotificationDefaultSoundName;
    //notification.applicationIconBadgeNumber = 10;

    [[UIApplication sharedApplication] scheduleLocalNotification:notification];


}
于 2016-04-07T04:35:12.000 に答える