Skip to content

Commit

Permalink
Update bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
khmMouna committed May 22, 2024
1 parent 064e1a8 commit 6747734
Show file tree
Hide file tree
Showing 6 changed files with 956 additions and 3,589 deletions.
2 changes: 1 addition & 1 deletion MauiSample/Platforms/iOS/AppDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public override bool FinishedLaunching(UIApplication application, NSDictionary l

Console.WriteLine("AirshipConfig: {0}", config);

UAirship.Push.ResetBadge();
UAirship.Push.ResetBadge(handler => {});

return base.FinishedLaunching(application, launchOptions);
}
Expand Down
5 changes: 3 additions & 2 deletions src/Airship.Net/IAirship.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ public interface IAirship

/// <summary>
/// Add/remove the push notification status listener.
/// Android only.
/// </summary>
event EventHandler<PushNotificationStatusEventArgs> OnPushNotificationStatusUpdate;

Expand Down Expand Up @@ -341,12 +342,12 @@ public interface IAirship
/// Gets or sets whether In-App Automation is paused.
/// </summary>
/// <value>Whether In-App Automation is paused.</value>
bool InAppAutomationPaused { get; set; }
//bool InAppAutomationPaused { get; set; }

/// <summary>
/// Gets or sets the In-App Automation display interval.
/// </summary>
/// <value>The display interval.</value>
TimeSpan InAppAutomationDisplayInterval { get; set; }
//TimeSpan InAppAutomationDisplayInterval { get; set; }
}
}
117 changes: 54 additions & 63 deletions src/Airship.Net/Platforms/iOS/Airship.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using UrbanAirship;
using AirshipDotNet.Analytics;
using AirshipDotNet.Attributes;
using static SystemConfiguration.NetworkReachability;

namespace AirshipDotNet
{
Expand All @@ -24,38 +25,26 @@ private void Initialize()
// Load unreferenced modules
AirshipAutomation.Init();

NSNotificationCenter.DefaultCenter.AddObserver(aName: (NSString)UAChannel.ChannelCreatedEvent, (notification) =>
NSNotificationCenter.DefaultCenter.AddObserver(aName: (NSString)UAirshipNotificationChannelCreated.Name, (notification) =>
{
string channelID = notification.UserInfo[UAChannel.ChannelIdentifierKey].ToString();
string channelID = notification.UserInfo?[UAirshipNotificationChannelCreated.ChannelIDKey].ToString();
OnChannelCreation?.Invoke(this, new ChannelEventArgs(channelID));
});

NSNotificationCenter.DefaultCenter.AddObserver(aName: (NSString)UAPush.NotificationStatusUpdateEvent, (notification) =>
{
OnPushNotificationStatusUpdate?.Invoke(this,
new PushNotificationStatusEventArgs(
notification.UserInfo[UAPush.IsUserNotificationsEnabled].Equals((NSNumber)1),
notification.UserInfo[UAPush.AreNotificationsAllowed].Equals((NSNumber)1),
notification.UserInfo[UAPush.IsPushPrivacyFeatureEnabled].Equals((NSNumber)1),
notification.UserInfo[UAPush.IsPushTokenRegistered].Equals((NSNumber)1),
notification.UserInfo[UAPush.IsUserOptedIn].Equals((NSNumber)1),
notification.UserInfo[UAPush.IsOptedIn].Equals((NSNumber)1)
)
);
});


//Adding Inbox updated Listener
NSNotificationCenter.DefaultCenter.AddObserver(aName: (NSString)"com.urbanairship.notification.message_list_updated", (notification) =>
NSNotificationCenter.DefaultCenter.AddObserver(aName: (NSString)UAirshipNotificationMessageCenterListUpdated.Name, (notification) =>
{
OnMessageCenterUpdated?.Invoke(this, EventArgs.Empty);
});

}

/// <summary>
/// Add/remove the channel creation listener.
/// </summary>
public event EventHandler<ChannelEventArgs>? OnChannelCreation;


/// <summary>
/// Add/remove the push notification status listener.
/// </summary>
Expand All @@ -71,15 +60,17 @@ public event EventHandler<DeepLinkEventArgs> OnDeepLinkReceived
add
{
onDeepLinkReceived += value;
UAirship.Shared.WeakDeepLinkDelegate = this;
//FIXME:
UAirship.WeakDeepLinkDelegate = this;
}
remove
{
onDeepLinkReceived -= value;

if (onDeepLinkReceived == null)
{
UAirship.Shared.WeakDeepLinkDelegate = null;
// FIXME:
//UAirship.Shared.WeakDeepLinkDelegate = null;
}
}
}
Expand Down Expand Up @@ -122,15 +113,15 @@ public bool UserNotificationsEnabled

public Features EnabledFeatures
{
get => FeaturesFromUAFeatures(UAirship.Shared.PrivacyManager.EnabledFeatures);
set => UAirship.Shared.PrivacyManager.EnabledFeatures = UaFeaturesFromFeatures(value);
get => FeaturesFromUAFeatures(UAirship.PrivacyManager.EnabledFeatures);
set => UAirship.PrivacyManager.EnabledFeatures = UaFeaturesFromFeatures(value);
}

public void EnableFeatures(Features features) =>
UAirship.Shared.PrivacyManager.EnableFeatures(UaFeaturesFromFeatures(features));
UAirship.PrivacyManager.EnableFeatures(UaFeaturesFromFeatures(features));

public void DisableFeatures(Features features) =>
UAirship.Shared.PrivacyManager.DisableFeatures(UaFeaturesFromFeatures(features));
UAirship.PrivacyManager.DisableFeatures(UaFeaturesFromFeatures(features));

public bool IsFeatureEnabled(Features feature) => EnabledFeatures.HasFlag(feature);

Expand Down Expand Up @@ -206,7 +197,10 @@ private static Features FeaturesFromUAFeatures(UAFeatures uAFeatures)

public void GetNamedUser(Action<string> namedUser)
{
UAirship.Contact.GetNamedUserID(namedUser);
UAirship.Contact.GetNamedUserID(user =>
{
namedUser(user);
});
}

public void ResetContact() => UAirship.Contact.Reset();
Expand All @@ -222,9 +216,12 @@ private void DeviceTagHelper(bool clear, string[] addTags, string[] removeTags)
UAirship.Channel.Tags = Array.Empty<string>();
}

UAirship.Channel.AddTags(addTags);
UAirship.Channel.RemoveTags(removeTags);
UAirship.Push.UpdateRegistration();
UAirship.Channel.EditTags(editor =>
{
editor.AddTags(addTags);
editor.RemoveTags(removeTags);
editor.Apply();
});
}

public void AddCustomEvent(CustomEvent customEvent)
Expand Down Expand Up @@ -287,7 +284,7 @@ public void AddCustomEvent(CustomEvent customEvent)
}
}

UAirship.Analytics.AddEvent(uaEvent);
UAirship.Analytics.RecordCustomEvent(uaEvent);
}

public void TrackScreen(string screen) => UAirship.Analytics.TrackScreen(screen);
Expand Down Expand Up @@ -390,11 +387,30 @@ public void InboxMessages(Action<List<MessageCenter.Message>> listMessages)

public Channel.TagGroupsEditor EditChannelTagGroups()
{
return new(payload =>
return new(operations =>
{
ChannelTagGroupHelper(payload, () =>
UAirship.Channel.EditTagGroups(editor =>
{
UAirship.Push.UpdateRegistration();
var channelActions = new Dictionary<Channel.TagGroupsEditor.OperationType, Action<string, string[]>>()
{
{ Channel.TagGroupsEditor.OperationType.ADD, (group, t) => editor.AddTags(t, group) },
{ Channel.TagGroupsEditor.OperationType.REMOVE, (group, t) => editor.RemoveTags(t, group) },
{ Channel.TagGroupsEditor.OperationType.SET, (group, t) => editor.SetTags(t, group) }
};

foreach (Channel.TagGroupsEditor.TagOperation operation in operations)
{
if (!Enum.IsDefined(typeof(Channel.TagGroupsEditor.OperationType), operation.operationType))
{
continue;
}

string[] tagArray = new string[operation.tags.Count];
operation.tags.CopyTo(tagArray, 0);
channelActions[operation.operationType](operation.group, tagArray);
}

editor.Apply();
});
});
}
Expand Down Expand Up @@ -564,34 +580,6 @@ private void ContactTagGroupHelper(List<Channel.TagGroupsEditor.TagOperation> op
});
}

private void ChannelTagGroupHelper(List<Channel.TagGroupsEditor.TagOperation> operations, Action finished)
{
UAirship.Channel.EditTagGroups(editor =>
{
var channelActions = new Dictionary<Channel.TagGroupsEditor.OperationType, Action<string, string[]>>()
{
{ Channel.TagGroupsEditor.OperationType.ADD, (group, t) => editor.AddTags(t, group) },
{ Channel.TagGroupsEditor.OperationType.REMOVE, (group, t) => editor.RemoveTags(t, group) },
{ Channel.TagGroupsEditor.OperationType.SET, (group, t) => editor.SetTags(t, group) }
};

foreach (Channel.TagGroupsEditor.TagOperation operation in operations)
{
if (!Enum.IsDefined(typeof(Channel.TagGroupsEditor.OperationType), operation.operationType))
{
continue;
}

string[] tagArray = new string[operation.tags.Count];
operation.tags.CopyTo(tagArray, 0);
channelActions[operation.operationType](operation.group, tagArray);
}

editor.Apply();
finished();
});
}

private void ApplyChannelSubscriptionListHelper(List<Channel.SubscriptionListEditor.SubscriptionListOperation> operations)
{
UAirship.Channel.EditSubscriptionLists(editor =>
Expand Down Expand Up @@ -682,17 +670,20 @@ public void OnDismissMessageCenter()
{
}

/**
// FIXME: Need to be exposed from iOS SDK
public bool InAppAutomationPaused
{
get => UAInAppAutomation.Shared.Paused;
set => UAInAppAutomation.Shared.Paused = value;
}
// FIXME: Need to be exposed from iOS SDK
public TimeSpan InAppAutomationDisplayInterval
{
get => TimeSpan.FromSeconds(UAInAppAutomation.Shared.InAppMessageManager.DisplayInterval);
set => UAInAppAutomation.Shared.InAppMessageManager.DisplayInterval = value.TotalSeconds;
get => TimeSpan.FromSeconds(UAInAppAutomation.Shared.InAppMessaging.DisplayInterval);
set => UAInAppAutomation.Shared.InAppMessaging.DisplayInterval = value.TotalSeconds;
}

**/
}
}
Loading

0 comments on commit 6747734

Please sign in to comment.