私のアプリケーションでは、特定の日付の午後12時および午後6時の偽の通知をトリガーする必要があります。私は "UILocalNotification"カテゴリファイルにローカル通知を作成し、予定しています。12PMと6PMの特定の日付のローカル通知を設定する方法
UILocalNotification + TZT.hファイル:
#import <UIKit/UIKit.h>
@interface UILocalNotification (TZT)
//Create LocalNotification
+ (void)createLocalNotificaitonForDateForDate:(NSDate *)date
withBody:(NSString *)body
withUserInfo:(NSDictionary *)userInfo
withTimeInterValInfo:(NSArray *)timeInterValInfo
withBtnTitle:(NSString *)btnTitle;
//Cancel All Local notificaitons
+ (void)cancelAllLocalNotifications;
@end
UILocalNotification + TZT.mファイル:
#import "UILocalNotification+TZT.h"
@implementation UILocalNotification (TZT)
+ (void)createLocalNotificaitonForDateForDate:(NSDate *)date
withBody:(NSString *)body
withUserInfo:(NSDictionary *)userInfo
withTimeInterValInfo:(NSArray *)timeInterValInfo
withBtnTitle:(NSString *)btnTitle
{
UILocalNotification * localNotification = [[UILocalNotification alloc] init];
localNotification.alertBody = body;
localNotification.alertAction = btnTitle;
localNotification.userInfo = userInfo;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.repeatInterval = 0;
localNotification.soundName = UILocalNotificationDefaultSoundName;
for (int i = 0; i < [timeInterValInfo count]; i++) {
NSLog(@"timeInterValInfo = %ld",(long)[[timeInterValInfo objectAtIndex:i] integerValue]);
date = [date dateByAddingTimeInterval:(long)[[timeInterValInfo objectAtIndex:i] integerValue]];
localNotification.fireDate = date;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}
//localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
}
+ (void)cancelAllLocalNotifications
{
[[UIApplication sharedApplication] cancelAllLocalNotifications];
}
AppdelegateクラスdidFinishLaunchingWithOptions方法では、私が作成し、スケジュールする必要がありますカテゴリクラスを呼び出すことによるローカル通知。例えば
#pragma mark - UILocalNotification
- (void)setUpLocalNotification
{
NSDate * firedDate = [TZTNSDateHandlings getDateMonthYearHyPhenFormat:@"31-07-2017 00:00:00" withHourMinSec:YES];
NSArray * timeInterValArray = @[@"43200",@"64800"];
NSDictionary * userInfoDic = @{@"receiverType":@"localNotification"
};
[UILocalNotification createLocalNotificaitonForDateForDate:firedDate
withBody:@"Sample local notification"
withUserInfo:userInfoDic
withTimeInterValInfo:timeInterValArray
withBtnTitle:NSLocalizedString(@"localPush.btnTitle", nil)];
}
、7月31日午後12時と午後6時に私はローカル通知を表示したい、だから、私はNSArrayのはNSTimeInterVal値が含まれて作成した後、NSDateに変換、文字列として静的日付を設定します。
12PMとして43200秒、また、これらの時間間隔値でスケジュールされた64800秒として6PMとなります。
しかし、デバイスと同様にローカル通知シミュレータも表示されません。
アプリケーション・デプロイメントのターゲットは、だから私はiOSの9.0以下とiOSのための10のローカル通知を管理し、ケースの上にする必要があるのiOS 9.0
から始まりますか?
私はiOS-10命令にも従う必要がありますか?
私に親切にお勧めします。
ご回答いただきありがとうございます。よろしくお願いします。 は、iOS 9.0からの展開を開始した場合でも、すべてのデバイスをUILocalNotificationで起動できますか?それ以外の場合は、別の方法でiOS 10.0のローカル通知を統合する必要がありますか? – Ram
ローカル通知は、 {fire date = 2017年7月29日土曜日午後6時00分(インド標準時、タイムゾーン=アジア/カルカッタ(GMT + 5:30)オフセット19800 、繰り返し間隔= 0、繰り返し回数= UILocalNotificationInfiniteRepeatCount、次の発砲日= 2017年7月29日土曜日午後6時00分(インド標準時、ユーザー情報=(ヌル)) ローカル通知のアラートは表示されません。私はシミュレータでテストしました。 デバイスでのみローカル通知を表示できますか? –
Ram
ローカル通知は、シミュレータとデバイスの両方で動作しています。AppDelegateのdidReceiveLocalNotificationメソッドでチェックする必要があります。 –