Month: January 2017

Xamarin.Forms – iOS/iPhone – Detecting if user said no to push/remote notifications

I assume if you’re reading this, you’re familiar with dependency injection in Xamarin Forms. What you’d create in your portable project (Your Xamarin Forms application) is the following

Xamarin.Forms custom class

public interface INotificationsInterface
{
    bool registeredForNotifications();
}

In your Xamarin.iOS project,  implement the interface with the following:

public class NotificationsInterface: INotificationsInterface
{
	public bool registeredForNotifications()
	{
		UIUserNotificationType types = UIApplication.SharedApplication.CurrentUserNotificationSettings.Types;
		if (types.HasFlag(UIUserNotificationType.Alert))
		{
			return true;
		}
		return false;
	}
}

In your main activity for your Xamarin.Forms application, perform the check as follows:

if (DependencyService.Get().registeredForNotifications())
{
	Debug.WriteLine("alerts enabled!");
} else
{
	String warningAboutAlerts ="The point of this applications is instant alerts" +
" but you choose not to receive alerts. You will need to manually check the notifications" +
	   "page or go into your iPhone's system settings to reenable alerts";
	Debug.WriteLine("No alerts allowed!");
	mainLayout.Children.Add(new Label
	{
		Text = warningAboutAlerts,
		TextColor = Color.Red,
		FontSize = 14
	});
	
}

Fairly simple stuff! For my code above, replace mainlayout with whatever you want… a dialogue box, disabling/enabling menu items… it’s entirely up to yourself!

 

 

Current Status of Canadian Classifieds Alerter for iOS/iPhone

Link to download Canadian Classifieds Alerter: iOS(iPhone) Port

Current status: Running!

Current alert refresh rate: 18-20 minutes

If you want faster alerts, message me!

Monthly pricing is as follows:

   $80 for every ten seconds
   $65 for every 45 seconds
   $40 for every two minutes
   $20 for every five minutes

Sidenote: Don’t ever assume I know about a bug. If you’re having an issue, I need to know!

 

Link to download Canadian Classifieds Alerter: iOS(iPhone) Port