Local notifications on a timer in IOS xamarin forms

xardalodinxardalodin ✭✭Member ✭✭
    public void start()
            {
                DateTime x = DateTime.Now.ToLocalTime();

                var notification = new UILocalNotification
                {
                    AlertTitle = "SmartSourching",
                    AlertBody = "hello world" + test.ToString(),
                    SoundName = UILocalNotification.DefaultSoundName,
                    FireDate = x.ToNSDate(),
                    RepeatInterval = NSCalendarUnit.Minute,
                    UserInfo = NSDictionary.FromObjectAndKey(NSObject.FromObject(0), NSObject.FromObject(NotificationKey))
                };
                test++;
                UIApplication.SharedApplication.ScheduleLocalNotification(notification);

            }

hi this code does create a repeating notification in ios12.2 simulator.. iphone5

though the exact same notification test++ does nothing. its always hello world0;

so how do I. In IOs create a timer instead of the RepeatInterval. (alarm manager in android equvilent)

tried NSTimer var timer = NSTimer.CreateScheduledTimer(60, (_) => start()); which does nothing..

had to add quite alot to appdelegate to get it to work.(dont know what it does but works.)

I dont know what Iam doing in IOs.

Best Answer

  • xardalodinxardalodin ✭✭ ✭✭
    Accepted Answer
      public void StartTimer()
            {
                TimeSpan interval = new TimeSpan(0, 0, 1, 0, 0);
    
                NSTimer timer = NSTimer.CreateRepeatingTimer(interval, t =>
                {
                    start4();
                });
                NSRunLoop.Main.AddTimer(timer, NSRunLoopMode.Common);
            }
    

    ok this worked 1 min

Answers

  • xardalodinxardalodin ✭✭ Member ✭✭
    Accepted Answer
      public void StartTimer()
            {
                TimeSpan interval = new TimeSpan(0, 0, 1, 0, 0);
    
                NSTimer timer = NSTimer.CreateRepeatingTimer(interval, t =>
                {
                    start4();
                });
                NSRunLoop.Main.AddTimer(timer, NSRunLoopMode.Common);
            }
    

    ok this worked 1 min

Sign In or Register to comment.