2017-05-03 10 views
0

ローカルの通知が必要なアプリを開発中です。私は複数のオブジェクトを持つテキストの配列を持っており、私は毎日配列のすべての要素を起動する必要があります。 私はこれに多くの問題に直面しています。たびに、配列から1つの通知だけを起動する必要があります。 これを手伝ってください。iosで毎日ランダムなローカル通知を毎日発射する方法

UILocalNotification * notification = [[UILocalNotification alloc] init];

 notification.fireDate = fireDateOfNotification; 
     notification.timeZone = [NSTimeZone localTimeZone]; 
     NSString *myString = SelectedAffirmationText; 
     NSArray *myArray = [myString componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@","]]; 
     //NSString *StrForNotification=[myArray objectAtIndex:0]; 

     for(int i=0;i<myArray.count;i++) 
     { 
      NSString *StrForNotification=[myArray objectAtIndex:i]; 
     notification.alertBody = [NSString stringWithFormat: @"%@",StrForNotification]; 
     } 


     notification.alertAction = @"go back"; 
     NSDictionary *userDict = [NSDictionary dictionaryWithObjectsAndKeys:DateSelected, @"Date", TimeSelected, @"Time",SelectedAffirmationText,@"DataAffiramtion", nil]; 

     notification.userInfo = userDict; 
     notification.repeatInterval= NSDayCalendarUnit; 
     notification.soundName = UILocalNotificationDefaultSoundName; 
     [[UIApplication sharedApplication] scheduleLocalNotification:notification]; 
+0

作業中のコードをいくつか追加してください。 – Arun

+0

@Arunはコードを追加しました.goを使って答えを提案します –

+0

このリンクをお試しください。これはあなたに役立つかもしれません[1日あたりのローカル通知を発する](http://stackoverflow.com/questions/13296190/local-notification-everyday-at -700am-not-notifying) – Arun

答えて

0

iOS 10.0の場合、以下のようにローカル通知に時間を追加してください。あなたは、トリガーを今すぐ

let content = UNMutableNotificationContent() 
content.title = "Title" 
content.subtitle = "Subtitle" 
content.body = "Some body." 
content.badge = 1 
content.sound = UNNotificationSound.default() 

UNNotificationRequestを作成するには、以下のようなコンテンツを作成し、コンテンツを渡す通知フレームワーク

var date = DateComponents() 
date.hour = 22 
let calendarTrigger = UNCalendarNotificationTrigger(dateMatching: date, repeats: true) 

を追加する必要があります。

現在、UserNotificationsフレームワークは、あなたのための3つが用意されています。通知することができます

UNTimeIntervalNotificationTriggerは、それをスケジュールした後、時間の設定量を送信します。

UNCalendarNotificationTrigger:UNCalendarNotificationTriggerは、スケジュールされた日時に関係なく、特定の日時に通知を送信できるようにします。

UNLocationNotificationTrigger:UNLocationNotificationTriggerは、ユーザーが指定された地理的領域に入ったり出たりしたときに通知を送信できるようにします。

+0

Plzがコードを通り、私に答えを提案します –

関連する問題