Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
freever committed Jul 28, 2023
1 parent 66f1bc5 commit 204d1a8
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 18 deletions.
50 changes: 38 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,31 +197,53 @@ You might need to delete and reinstall the app to get a Pns Handle!

#### AppDelegate.cs

In FinishedLaunching, after the call to LoadApplication, call
Amend AppDelegate as follows:

```c#
AppServiceLocator.Resolve<IosPushNotificationHandler>().InitializeAsync(this, options);
```
private NSDictionary _launchOptions;

protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(s =>
{
s.AddPushNotificationsClient<PushNotificationsTapHandler>();
s.AddTransient(_=> new StartupTasks(async ()=>
{
await AppServiceLocator.Resolve<IosPushNotificationHandler>()
.InitializeAsync(this, _launchOptions);
}));
});

Add overrides for notification event handlers:
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
_launchOptions = launchOptions;
return base.FinishedLaunching(application, launchOptions);
}

```c#
public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
[Export("application:didRegisterForRemoteNotificationsWithDeviceToken:")]
public void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
{
AppServiceLocator.Resolve<IosPushNotificationHandler>()
.HandleNewToken(deviceToken);
}

public override void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
[Export("application:didFailToRegisterForRemoteNotificationsWithError:")]
public void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
{
AppServiceLocator.Resolve<IosPushNotificationHandler>()
.HandleFailedRegistration(error);
}

public override void ReceivedRemoteNotification(UIApplication application, NSDictionary options)
[Export("application:didReceiveRemoteNotification:fetchCompletionHandler:")]
public void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
{
AppServiceLocator.Resolve<IosPushNotificationHandler>()
.HandleMessageReceivedAsync(application.ApplicationState, userInfo);
}

[Export("application:didReceiveRemoteNotification:")]
public void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo)
{
AppServiceLocator.Resolve<IosPushNotificationHandler>()
.HandleMessageReceivedAsync(application.ApplicationState, options);
.HandleMessageReceivedAsync(application.ApplicationState, userInfo);
}
```

Expand All @@ -232,10 +254,14 @@ public override void ReceivedRemoteNotification(UIApplication application, NSDic
<string>production</string>
```

#### Service registration

Register the iOS dependencies with the Service Collection using services.AddIosPushNotifications();
#### Info.plist:

```xml
<key>UIBackgroundModes</key>
<array>
<string>remote-notification</string>
</array>
```

## UWP

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@


<ItemGroup>
<PackageReference Include="Blauhaus.DeviceServices.Abstractions" Version="1.2.18" />
<PackageReference Include="Blauhaus.DeviceServices.Abstractions" Version="1.2.19" />
</ItemGroup>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Blauhaus.DeviceServices.Abstractions" Version="1.2.18" />
<PackageReference Include="Blauhaus.Ioc.Abstractions" Version="1.5.3" />
<PackageReference Include="Blauhaus.DeviceServices.Abstractions" Version="1.2.19" />
<PackageReference Include="Blauhaus.Ioc.Abstractions" Version="1.5.4" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
<PackageReference Include="System.Reactive" Version="6.0.0" />
Expand Down
4 changes: 2 additions & 2 deletions src/Blauhaus.Push.Client/Blauhaus.Push.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
<ItemGroup>
<PackageReference Include="Blauhaus.Common.Configuration" Version="2.3.18" />
<PackageReference Include="Blauhaus.Common.Utils" Version="2.3.18" />
<PackageReference Include="Blauhaus.DeviceServices.Abstractions" Version="1.2.18" />
<PackageReference Include="Blauhaus.Ioc.Abstractions" Version="1.5.3" />
<PackageReference Include="Blauhaus.DeviceServices.Abstractions" Version="1.2.19" />
<PackageReference Include="Blauhaus.Ioc.Abstractions" Version="1.5.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
Expand Down
2 changes: 1 addition & 1 deletion src/Blauhaus.Push.Tests.Server/Blauhaus.Push.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<PackageReference Include="Blauhaus.Analytics.TestHelpers" Version="2.0.10" />
<PackageReference Include="Blauhaus.DeviceServices.TestHelpers" Version="1.2.18" />
<PackageReference Include="Blauhaus.DeviceServices.TestHelpers" Version="1.2.19" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="nunit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0">
Expand Down

0 comments on commit 204d1a8

Please sign in to comment.