Skip to content

Commit

Permalink
WIP on new bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
aritchie committed May 25, 2024
1 parent f15a4a5 commit c853529
Show file tree
Hide file tree
Showing 28 changed files with 224 additions and 182 deletions.
31 changes: 13 additions & 18 deletions Shiny.sln
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libs", "libs", "{6374E4D9-1
src\nuget.png = src\nuget.png
src\nuget.txt = src\nuget.txt
version.json = version.json
src\firebase_ios\Firebase-ios.targets = src\firebase_ios\Firebase-ios.targets
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{3A15354E-BAD2-4195-BE6B-49ED2B4E56E6}"
Expand Down Expand Up @@ -105,14 +106,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shiny.SourceGenerators.Test
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shiny.SourceGenerators", "src\Shiny.SourceGenerators\Shiny.SourceGenerators.csproj", "{A44BB6F8-283F-4FD7-9955-41B6B515AC98}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "firebase-ios", "firebase-ios", "{5418A62F-B22B-4963-B4E4-8B4ECE436EC9}"
ProjectSection(SolutionItems) = preProject
src\firebase_ios\Firebase-ios.targets = src\firebase_ios\Firebase-ios.targets
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shiny.Firebase.Analytics.Binding", "src\firebase_ios\Shiny.Firebase.Analytics.Binding\Shiny.Firebase.Analytics.Binding.csproj", "{161A2886-7EC4-496B-AE9A-A8D8E9061100}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shiny.Firebase.Analytics.iOS.Binding", "src\Shiny.Firebase.Analytics.iOS.Binding\Shiny.Firebase.Analytics.iOS.Binding.csproj", "{95304E51-AD99-41EA-A007-16F6FDCEC779}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shiny.Firebase.Messaging.Binding", "src\firebase_ios\Shiny.Firebase.Messaging.Binding\Shiny.Firebase.Messaging.Binding.csproj", "{6C63C86E-DC5D-4B60-AA14-A347B3932972}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shiny.Firebase.Messaging.iOS.Binding", "src\Shiny.Firebase.Messaging.iOS.Binding\Shiny.Firebase.Messaging.iOS.Binding.csproj", "{F7E69503-E920-4E1E-8F7C-358DD7982738}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -223,14 +219,14 @@ Global
{A44BB6F8-283F-4FD7-9955-41B6B515AC98}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A44BB6F8-283F-4FD7-9955-41B6B515AC98}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A44BB6F8-283F-4FD7-9955-41B6B515AC98}.Release|Any CPU.Build.0 = Release|Any CPU
{161A2886-7EC4-496B-AE9A-A8D8E9061100}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{161A2886-7EC4-496B-AE9A-A8D8E9061100}.Debug|Any CPU.Build.0 = Debug|Any CPU
{161A2886-7EC4-496B-AE9A-A8D8E9061100}.Release|Any CPU.ActiveCfg = Release|Any CPU
{161A2886-7EC4-496B-AE9A-A8D8E9061100}.Release|Any CPU.Build.0 = Release|Any CPU
{6C63C86E-DC5D-4B60-AA14-A347B3932972}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6C63C86E-DC5D-4B60-AA14-A347B3932972}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6C63C86E-DC5D-4B60-AA14-A347B3932972}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6C63C86E-DC5D-4B60-AA14-A347B3932972}.Release|Any CPU.Build.0 = Release|Any CPU
{95304E51-AD99-41EA-A007-16F6FDCEC779}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{95304E51-AD99-41EA-A007-16F6FDCEC779}.Debug|Any CPU.Build.0 = Debug|Any CPU
{95304E51-AD99-41EA-A007-16F6FDCEC779}.Release|Any CPU.ActiveCfg = Release|Any CPU
{95304E51-AD99-41EA-A007-16F6FDCEC779}.Release|Any CPU.Build.0 = Release|Any CPU
{F7E69503-E920-4E1E-8F7C-358DD7982738}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F7E69503-E920-4E1E-8F7C-358DD7982738}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F7E69503-E920-4E1E-8F7C-358DD7982738}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F7E69503-E920-4E1E-8F7C-358DD7982738}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -263,9 +259,8 @@ Global
{C21631E7-A789-4DF8-B83F-03D6A07B57B4} = {7C114E37-36C8-4971-91C6-E2557DDCB4E8}
{4B31F220-D152-40A7-8D0F-2FABA7C3926C} = {7C114E37-36C8-4971-91C6-E2557DDCB4E8}
{A44BB6F8-283F-4FD7-9955-41B6B515AC98} = {6374E4D9-1BD8-4880-B603-AFDEA8345D7E}
{5418A62F-B22B-4963-B4E4-8B4ECE436EC9} = {6374E4D9-1BD8-4880-B603-AFDEA8345D7E}
{161A2886-7EC4-496B-AE9A-A8D8E9061100} = {5418A62F-B22B-4963-B4E4-8B4ECE436EC9}
{6C63C86E-DC5D-4B60-AA14-A347B3932972} = {5418A62F-B22B-4963-B4E4-8B4ECE436EC9}
{95304E51-AD99-41EA-A007-16F6FDCEC779} = {6374E4D9-1BD8-4880-B603-AFDEA8345D7E}
{F7E69503-E920-4E1E-8F7C-358DD7982738} = {6374E4D9-1BD8-4880-B603-AFDEA8345D7E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {135D86AF-4EC4-4AA0-BD06-75C410F3EA08}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using Foundation;

namespace Shiny.Firebase.Analytics.Binding
namespace Shiny.Firebase.Analytics.iOS.Binding
{
[BaseType(typeof(NSObject))]
interface FirebaseApplication
Expand All @@ -11,42 +11,39 @@ interface FirebaseApplication
void AutoConfigure();

[Static]
[Export("configure:gcmSenderId:")]
void Configure(string googleAppId, string gcmSenderId);
[Export("configure:gcmSenderId:apiKey:projectId")]
bool Configure(string googleAppId, string gcmSenderId, string? apiKey, string? projectId);

[Static]
[Export("isConfigured")]
bool IsConfigured { get; }
}


// @interface FirebaseAnalytics : NSObject
[BaseType (typeof(NSObject))]
interface FirebaseAnalytics
{
// -(void)logEventWithEventName:(NSString * _Nonnull)eventName parameters:(NSDictionary<NSString *,id> * _Nonnull)parameters;
[Static]
[Export ("logEventWithEventName:parameters:")]
void LogEvent (string eventName, NSDictionary<NSString, NSObject> parameters);

// -(void)getAppInstanceIdWithCompletion:(void (^ _Nonnull)(NSString * _Nullable))completion;
[Static]
[Export ("getAppInstanceIdWithCompletion:")]
[Async]
void GetAppInstanceId (Action<NSString> completion);

// -(void)setUserIdWithUserId:(NSString * _Nonnull)userId;
[Static]
[Export ("setUserIdWithUserId:")]
void SetUserId (string userId);

// -(void)setUserPropertyWithPropertyName:(NSString * _Nonnull)propertyName value:(NSString * _Nonnull)value;
[Static]
[Export ("setUserProperty:value:")]
void SetUserProperty (string propertyName, string value);

// -(void)setSessionTimeoutWithSeconds:(NSInteger)seconds;
[Static]
[Export ("setSessionTimeoutWithSeconds:")]
void SetSessionTimeout (nint seconds);

// -(void)resetAnalyticsData;
[Static]
[Export ("resetAnalyticsData")]
void ResetAnalyticsData ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@
<ImplicitUsings>true</ImplicitUsings>
<IsBindingProject>true</IsBindingProject>

<XcodeProject>$(MSBuildThisFileDirectory)../native/analytics/MauiFirebaseAnalytics.xcodeproj</XcodeProject>
<XcodeProject>$(MSBuildThisFileDirectory)../firebase_ios/native/analytics/ShinyFirebaseAnalytics.xcodeproj</XcodeProject>
<XcodeBuildXCFramework>true</XcodeBuildXCFramework>
<ObjSharpieBind>False</ObjSharpieBind>
<ObjSharpieBindNamespace>Firebase</ObjSharpieBindNamespace>
</PropertyGroup>

<ItemGroup>
<ObjcBindingApiDefinition Include="ApiDefinitions.cs" />
<NativeReference Include="../native/analytics/.build/MauiFirebaseAnalytics.xcframework">
<NativeReference Include="$(MSBuildThisFileDirectory)../firebase_ios/native/analytics/.build/ShinyFirebaseAnalytics.xcframework">
<Kind>Framework</Kind>
<SmartLink>True</SmartLink>
</NativeReference>
</ItemGroup>

<Import Project="$(MSBuildThisFileDirectory)..\Firebase-ios.targets" />
<Import Project="$(MSBuildThisFileDirectory)..\firebase_ios\Firebase-ios.targets" />
</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using Foundation;

namespace Shiny.Firebase.Messaging.Binding
namespace Shiny.Firebase.Messaging.iOS.Binding
{
[BaseType(typeof(NSObject))]
interface FirebaseMessaging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@
<IsBindingProject>true</IsBindingProject>
<NoBindingEmbedding>true</NoBindingEmbedding>

<XcodeProject>$(MSBuildThisFileDirectory)../native/messaging/MauiFirebaseMessaging.xcodeproj</XcodeProject>
<XcodeProject>$(MSBuildThisFileDirectory)../firebase_ios/native/messaging/ShinyFirebaseMessaging.xcodeproj</XcodeProject>
<ObjSharpieBind>False</ObjSharpieBind>
</PropertyGroup>

<ItemGroup>
<ObjcBindingApiDefinition Include="ApiDefinitions.cs" />
<NativeReference Include="../native/messaging/.build/MauiFirebaseMessaging.xcframework">
<NativeReference Include="$(MSBuildThisFileDirectory)../firebase_ios/native/messaging/.build/ShinyFirebaseMessaging.xcframework">
<Kind>Framework</Kind>
<SmartLink>True</SmartLink>
<ForceLoad>True</ForceLoad>
</NativeReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Shiny.Firebase.Analytics.Binding\Shiny.Firebase.Analytics.Binding.csproj" />
<ProjectReference Include="..\Shiny.Firebase.Analytics.iOS.Binding\Shiny.Firebase.Analytics.iOS.Binding.csproj" />
</ItemGroup>

<Import Project="$(MSBuildThisFileDirectory)..\Firebase-ios.targets" />
<Import Project="$(MSBuildThisFileDirectory)..\firebase_ios\Firebase-ios.targets" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,30 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Firebase.CloudMessaging;
using Firebase.Core;
using Shiny.Firebase.Messaging.iOS.Binding;
using Foundation;

namespace Shiny.Push;


public class FirebasePushProvider : NotifyPropertyChanged, IPushProvider, IPushTagSupport
public class FirebasePushProvider(FirebaseConfiguration config) : NotifyPropertyChanged, IPushProvider, IPushTagSupport
{
readonly FirebaseConfiguration config;


public FirebasePushProvider(FirebaseConfiguration config)
{
this.config = config;
}


public async Task<string> Register(NSData nativeToken)
{
this.TryStartFirebase();

Messaging.SharedInstance.ApnsToken = nativeToken;
var fcmToken = await Messaging.SharedInstance.FetchTokenAsync();

var fcmToken = await FirebaseMessaging.RegisterAsync(nativeToken);
if (fcmToken == null)
throw new InvalidOperationException("FCM Token is null");

throw new InvalidOperationException("FCM Token is null");
return fcmToken;
}


public Task UnRegister()
{
this.RegisteredTags = null;
return Messaging.SharedInstance.DeleteTokenAsync();
return FirebaseMessaging.UnRegisterAsync();
}


Expand All @@ -54,19 +42,15 @@ public async Task AddTag(string tag)
var tags = this.RegisteredTags?.ToList() ?? new List<string>(1);
tags.Add(tag);

await Messaging
.SharedInstance
.SubscribeAsync(tag)
.ConfigureAwait(false);
await FirebaseMessaging.SubscribeAsync(tag).ConfigureAwait(false);
this.RegisteredTags = tags.ToArray();
}


public async Task RemoveTag(string tag)
{
await Messaging
.SharedInstance
.UnsubscribeAsync(tag)
await FirebaseMessaging
.UnSubscribeAsync(tag)
.ConfigureAwait(false);

if (this.RegisteredTags != null)
Expand All @@ -84,9 +68,8 @@ public async Task ClearTags()
{
foreach (var tag in this.RegisteredTags)
{
await Messaging
.SharedInstance
.UnsubscribeAsync(tag)
await FirebaseMessaging
.UnSubscribeAsync(tag)
.ConfigureAwait(false);
}
}
Expand All @@ -107,27 +90,25 @@ public async Task SetTags(params string[]? tags)

protected virtual void TryStartFirebase()
{
if (App.DefaultInstance == null)
if (!FirebaseApplication.IsConfigured)
{
if (this.config.UseEmbeddedConfiguration)
if (config.UseEmbeddedConfiguration)
{
App.Configure();
if (Messaging.SharedInstance == null)
throw new ArgumentException("Failed to configure firebase messaging - ensure you have GoogleService-Info.plist included in your iOS project and that it is set to a BundleResource");

Messaging.SharedInstance!.AutoInitEnabled = true;
FirebaseApplication.AutoConfigure();
FirebaseMessaging.IsAutoInitEnabled = true;
}
else
{
App.Configure(new Options(
this.config.AppId!,
this.config.SenderId!
)
{
ApiKey = this.config.ApiKey,
ProjectId = this.config.ProjectId
});
FirebaseApplication.Configure(
config.AppId!,
config.SenderId!,
config.ApiKey,
config.ProjectId
);
}

if (!FirebaseApplication.IsConfigured)
throw new InvalidOperationException("Firebase Application failed to configure - please check your settings");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@
<Description>Shiny Push Integration - Google Firebase Cloud Messaging</Description>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<CreatePackage>false</CreatePackage>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<CreatePackage>false</CreatePackage>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Shiny.Push\Shiny.Push.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(IsIosBuild)' == 'true'">
<PackageReference Include="Xamarin.Firebase.iOS.CloudMessaging" Version="8.10.0.3" />
<!-- <ProjectReference Include="..\Shiny.Firebase.Analytics.iOS.Binding\Shiny.Firebase.Analytics.iOS.Binding.csproj" />-->
<ProjectReference Include="..\Shiny.Firebase.Messaging.iOS.Binding\Shiny.Firebase.Messaging.iOS.Binding.csproj" />
</ItemGroup>
</Project>

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit c853529

Please sign in to comment.