Skip to content

Commit

Permalink
iOS & Android support
Browse files Browse the repository at this point in the history
  • Loading branch information
rdelrosario committed Sep 10, 2017
1 parent 6547e7f commit 5894c21
Show file tree
Hide file tree
Showing 30 changed files with 2,171 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto

###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp

###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary

###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary

###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
32 changes: 32 additions & 0 deletions nuget/Plugin.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0"?>
<package >
<metadata minClientVersion="2.8.1">
<id>Plugin.PushNotification</id>
<version>0.0.9-alpha</version>
<title>Push Notification Plugin for Xamarin</title>
<authors>Rendy Del Rosario</authors>
<owners>crossgeeks</owners>
<licenseUrl>https://raw.githubusercontent.com/CrossGeeks/PushNotificationPlugin/master/LICENSE</licenseUrl>
<projectUrl>https://github.com/CrossGeeks/PushNotificationPlugin</projectUrl>
<iconUrl>https://github.com/CrossGeeks/PushNotificationPlugin/blob/master/art/icon.png?raw=true</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Receive and handle push notifications across Xamarin.iOS and Xamarin.Android</description>
<summary>Receive and handle push notifications across Xamarin.iOS and Xamarin.Android</summary>
<releaseNotes>Support for handling push notifications</releaseNotes>
<copyright>Copyright 2017</copyright>
<tags>iOS,Android,push notifications,pcl,xamarin,plugins,xam.pcl,fcm,apn</tags>
<dependencies>
<group targetFramework="MonoAndroid10">
<dependency id="Xamarin.GooglePlayServices.Base" version="42.1021.1" />
<dependency id="Xamarin.Firebase.Messaging" version="42.1021.1" />
</group>
</dependencies>
</metadata>
<files>
<!--NetStandard/PCL-->
<file src="..\src\Plugin.PushNotification\bin\Release\netstandard1.0\Plugin.PushNotification.*" target="lib\netstandard1.0" />
<file src="..\src\Plugin.PushNotification.Android\bin\Release\Plugin.PushNotification.*" target="lib\MonoAndroid10" />
<file src="..\src\Plugin.PushNotification.iOS\bin\iPhone\Release\Plugin.PushNotification.*" target="lib\Xamarin.iOS10" />
</files>
</package>

144 changes: 144 additions & 0 deletions src/Plugin.PushNotification.Abstractions/IPushNotification.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
using System;
using System.Collections.Generic;

namespace Plugin.PushNotification.Abstractions
{
public enum NotificationActionType
{
Default,
AuthenticationRequired, //Only applies for iOS
Foreground,
Destructive //Only applies for iOS
}
public class NotificationUserCategory
{
public string Category { get; }
public List<NotificationUserAction> Actions { get; }

public NotificationCategoryType Type { get; }

public NotificationUserCategory(string category, List<NotificationUserAction> actions, NotificationCategoryType type = NotificationCategoryType.Default)
{
Category = category;
Actions = actions;
Type = type;
}
}

public class NotificationUserAction
{
public string Id { get; }
public string Title { get; }
public NotificationActionType Type { get; }
public string Icon { get; }
public NotificationUserAction(string id, string title, NotificationActionType type = NotificationActionType.Default, string icon = "")
{
Id = id;
Title = title;
Type = type;
Icon = icon;
}
}

public enum NotificationCategoryType
{
Default,
Custom,
Dismiss
}

public delegate void PushNotificationTokenEventHandler(object source, PushNotificationTokenEventArgs e);

public class PushNotificationTokenEventArgs : EventArgs
{
public string Token { get; }

public PushNotificationTokenEventArgs(string token)
{
Token = token;
}

}

public delegate void PushNotificationErrorEventHandler(object source, PushNotificationErrorEventArgs e);

public class PushNotificationErrorEventArgs : EventArgs
{
public string Message { get; }

public PushNotificationErrorEventArgs(string message)
{
Message = message;
}

}

public delegate void PushNotificationDataEventHandler(object source, PushNotificationDataEventArgs e);

public class PushNotificationDataEventArgs : EventArgs
{
public IDictionary<string, string> Data { get; }

public PushNotificationDataEventArgs(IDictionary<string, string> data)
{
Data = data;
}

}


public delegate void PushNotificationResponseEventHandler(object source, PushNotificationResponseEventArgs e);

public class PushNotificationResponseEventArgs : EventArgs
{
public string Identifier { get; }

public IDictionary<string, string> Data { get; }

public NotificationCategoryType Type { get; }

public PushNotificationResponseEventArgs(IDictionary<string, string> data, string identifier = "", NotificationCategoryType type = NotificationCategoryType.Default)
{
Identifier = identifier;
Data = data;
Type = type;
}

}

/// <summary>
/// Interface for PushNotification
/// </summary>
public interface IPushNotification
{
/// <summary>
/// Notification handler to receive, customize notification feedback and provide user actions
/// </summary>
IPushNotificationHandler NotificationHandler { get; set; }
/// <summary>
/// Event triggered when token is refreshed
/// </summary>
event PushNotificationTokenEventHandler OnTokenRefresh;
/// <summary>
/// Event triggered when a notification is opened
/// </summary>
event PushNotificationResponseEventHandler OnNotificationOpened;
/// <summary>
/// Event triggered when a notification is received
/// </summary>
event PushNotificationDataEventHandler OnNotificationReceived;
/// <summary>
/// Event triggered when there's an error
/// </summary>
event PushNotificationErrorEventHandler OnNotificationError;
/// <summary>
/// Push notification token
/// </summary>
string Token { get; }

/// <summary>
/// Get all user notification categories
/// </summary>
NotificationUserCategory[] GetUserNotificationCategories();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Plugin.PushNotification.Abstractions
{
public interface IPushNotificationHandler
{
//Method triggered when an error occurs
void OnError(string error);
//Method triggered when a notification is opened
void OnOpened(NotificationResponse response);
//Method triggered when a notification is received
void OnReceived(IDictionary<string, string> parameters);
}
}
22 changes: 22 additions & 0 deletions src/Plugin.PushNotification.Abstractions/NotificationResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Plugin.PushNotification.Abstractions
{
public class NotificationResponse
{
public string Identifier { get; }

public IDictionary<string, string> Data { get; }

public NotificationCategoryType Type { get; }

public NotificationResponse(IDictionary<string, string> data, string identifier = "", NotificationCategoryType type = NotificationCategoryType.Default)
{
Identifier = identifier;
Data = data;
Type = type;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard1.0</TargetFramework>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>bin\Release\netstandard1.0\Plugin.PushNotification.Abstractions.xml</DocumentationFile>
<DebugType>full</DebugType>
<DebugSymbols>True</DebugSymbols>
</PropertyGroup>

</Project>
Loading

0 comments on commit 5894c21

Please sign in to comment.