Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Xamarin iOS Notifications (Dependency Service)

$
0
0

Hi,

I have a really weird problem, I hope you can help me.
I am implementing notifications in a Xamarin.Forms project, working in both android and iOS platform. To do so, I have to use Dependency Service, so I can make a native implementation of the notification for both platforms. In android it works ok, but in iOS, for some reason, when it enters the iOS method to make the notification, it just returns in the middle of the method without throwing any message or error, as if it was a "return" keyword. I proved what happened if I call that same method with the same parameters from another point of the app, and it works very well in that case, but it doesn't when I call it from the point where it is supposed to do it.

I show you the interface for the Dependency Service:

public interface INotificationsManager
{
    void GenerateNotification(string title, string content);
}

And where I call it in the Shared Project:

    public class ServConnection
    {
    INotificationsManager iNotManager;

        private ServConnection()
        {
        iNotManager = DependencyService.Get<INotificationsManager>();
        NotifyMessage();
    }

        private void NotifyMessage()
        {
        iNotManager.GenerateNotification("Test", "This is a message");
    }
}

This is the implementation in the iOS project:

    public void GenerateNotification(string title, string content)
    {
        UILocalNotification notification = new UILocalNotification
        {
            FireDate = NSDate.FromTimeIntervalSinceNow(0),
            AlertTitle = title,
            AlertAction = "View Alert",
            AlertBody = content,
            ApplicationIconBadgeNumber = 1,
            SoundName = UILocalNotification.DefaultSoundName
        };

        UIApplication.SharedApplication.ScheduleLocalNotification(notification);
    }

When it enters this method, it just doesn't get to the end. What can be wrong?


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>