Using ALAssetsLibraryChangedNotification in background with Xamarin iOS - c#

I am writing an app targeting iOS7 in Xamarin.iOS that is supposed to upload users' pictures to an online storage service as soon as he/she takes them. In order to do this, I set up an ALAssetsLibraryChangedNotification observer, like this:
NSNotificationCenter.DefaultCenter.AddObserver (ALAssetsLibrary.ChangedNotification, Callback);
and then defined a callback like this:
void Callback (NSNotification notification)
{
Console.WriteLine ("Received a notification ALAssetsLibrary : {0}", notification);
//Launch picture upload here
}
This works well, but only with the app open. Is there a way to make my app receive the notification (and process the upload) when it is backgrounded? I use iOS7 backgrounding for file transfers and long running tasks in other points of my app, but I wouldn't know how to apply this to the observer.
Extra question, I would also like to be able to filter out notifications received by this function so that I can launch my upload only if the operation is "new picture created" (currently I get notifications also when pictures are removed/edited/moved).
Thanks in advance for your replies :)

Related

FCM Message not Received on iOS App when sent to a topic

I want to send notifications with FCM to an iOS App. It works fine when I send it to the token, but it doesn't work when I send it to a topic. I tried subscribing the App to the topics using this:
string[] topics = { "all", "test" };
CrossFirebasePushNotification.Current.Subscribe(topics);
(This is using the Plugin.FirebasePushNotification) or using this:
string[] tokens = { e.Token };
FirebaseMessaging.DefaultInstance.SubscribeToTopicAsync(tokens, "test");
FirebaseMessaging.DefaultInstance.SubscribeToTopicAsync(tokens, "all");
(This is using FirebaseAdmin) It's both in the App.xaml.cs, the first one beeing under InitializeComponent(); and the second one beeing in OnTokenRefresh. It works fine on android, but not on iOS. Keep in mind, that e.Token is the Token. I even tried to subscribe in the AppDelegate.cs, but it didn't work there either. I think it could be because it tries to subscribe before I even said "Yes" on the device so it can send me Notifications. I'm using an iPhone SE with iOS 15.3.
Thanks for your help!
I figured it out. In the AppDelegate.cs you can override the RegisteredForRemoteNotifications and you can just subscribe there. This means, it will subscribe if the user grants the permission to send remote notifications. After that it worked perfectly.

Error 404 when using Xbox Live SDK Leaderboards

I’ve built a game (C#, UWP, Monogame) and want to integrate it with Xbox Live SDK (Microsoft.Xbox.Live.SDK.WinRT.UWP from NuGet).
Already got auth working but experiencing some problems with StatisticManager/Leaderboard.
What exactly am I doing:
Add user with StatisticManager.AddLocalUser(user) and wait for StatisticEventType.LocalUserAdded event from DoWork
Save score with StatisticManager.SetStatisticNumberData(user, leaderboardName, data) and wait for StatisticEventType.StatisticUpdateComplete event from DoWork
Get the leaderboard with StatisticManager.GetLeaderboard(user, leaderboardName, query) and wait for StatisticEventType.GetLeaderboardComplete event from DoWork
On step 3 I get a C++ exception:
“Not found (404)”.
[This looks very similar to this issue](Exceptions and Error 404 when using StatsManager
).
So I’ve already checked the sandbox ID, config file and leaderboard ID but still get the same result.
I did capture the traffic from HTTP monitoring and I see URL like:
"https://leaderboards.xboxlive.com/scids/{scid}/leaderboards/stat({leaderboardId})?xuid={myXboxId}&maxItems=5"
under development, you must change your Xbox SANDBOX from RETAIL to {your sandbox} using XboxLiveTools (you can find it in github).
after published you can switch it back to RETAIL,and if there is no data in leaderboard return result with zero row no exception throw
I fixed the same problem by myself

Lync SDK Start Audio Video Call with Send only UI Suppression mode

I am trying to build application for conferencing using Lync SDK in UI Suppression mode, the application is close to the Meet Now feature in lync so that one user will send his Video/Audio to all other users in conversation, my code is:
// Add conversation using
_LyncClient.ConversationManager.AddConversation();
// When Conversation added add participants
// User 1 will broadcast video/audio
_Conversation.AddParticipant(_LyncClient.ContactManager.GetContactByUri(user1));
// User 2 and User 3 will only recieve audio video
_Conversation.AddParticipant(_LyncClient.ContactManager.GetContactByUri(user2));
_Conversation.AddParticipant(_LyncClient.ContactManager.GetContactByUri(user3));
// Start the audio call from user1 machine
avModality.BeginConnect(AVCallback);
// When recieve the call in user2, user 3 stop mic using mute
_Conversation.SelfParticipant.BeginSetMute(true, (ar) =>
{
_Conversation.SelfParticipant.EndSetMute(ar);
}, _Conversation.SelfParticipant);
// and same technique for video
It works but i noticed that the performance of the call is affected each time a user enters the conversation and the conversation goes to Hold then Retrive states until user is added.
How Can I start a call in one way only send (not send recive), i tried the following:
avModality.BeginConnect(AVCallback, ChannelState.Send);
but it didn't work, also i have a look on the Conversation Properties, Moadilty Properties
but nothing looks helpful.
the only thing i found related is avModality.AudioChannel.State but i can't find a way to set this property?
Can anyone help?
I managed to create a one way video call by starting an audio call from the user who is sending the video and then in ModalityStateChanged calling avModality.VideoChannel.BeginStart once the call was connected.
Hope this helps.

Using BackgroundUploadAsync to upload file to SkyDrive after WP8 app has been closed

So I made a simple Windows Phone 8 app that uploads a text file to the user's SkyDrive account. My code works fine while my app is running in the foreground, but when I attempt to upload a text file when my app is closing , it doesn't seem to work.
I'm using the Live Connect SDK v5.3 for WP8.
SDK link: http://msdn.microsoft.com/en-us/library/live/hh826550.aspx
I'm using this piece of code to do the background upload when my app closes (when the user hits "back button" on their phone:
protected override void OnBackKeyPress(CancelEventArgs e)
{
SaveSkyDriveData();
base.OnBackKeyPress(e);
}
public async Task SaveSkyDriveData()
{
var res = await client.BackgroundUploadAsync("me/skydrive", new Uri("/shared/transfers/MyData.txt", UriKind.RelativeOrAbsolute), OverwriteOption.Overwrite);
}
Any ideas why this code doesn't work when the app is closing? I've read through the SDK that says this should work even after the app has been dismissed. Here's the SDK link for uploading files in the background: http://msdn.microsoft.com/en-us/library/live/hh826531.aspx#uploading_files
Thanks!
You cannot upload files during the closing of the app in WP as you only have about 10 seconds to save state before it's shutdown
You might be able to do it during de-activation but it would be a push as the timescales are the same.
A better solution would be to have a background task (scheduled task) that runs and checks for files to upload and does so periodically.
Another alternative depending on your use case would be to use the parse SDK rather than upload to SkyDrive unless there is a specific reason the file needs to be hosted on SkyDrive
Hope this helps
To revive an ancient thread, is this because you aren't awaiting your async task?
protected override **async** void OnBackKeyPress(CancelEventArgs e)
{
**await** SaveSkyDriveData();
base.OnBackKeyPress(e);
}
the compiler should be warning you that nothing is awaiting the task...
so nothing downstream knows that there's work in progress? so any async work that started probably doesn't complete before the app closes.
if that's related, there are other answers about waiting synchronously as well, like using Task.Run(() => SaveSkyDriveData()).Wait(); to make the async thing be synchronous,

Push Notifications with PushSharp - the basics

I need to push notifications to tens of thousands of iOS devices that my app installed. I'm trying to do it with PushSharp, but I'm missing some fundamental concepts here. At first I tried to actually run this in a Windows service, but couldn't get it work - getting null reference errors coming from _push.QueueNotification() call. Then I did exactly what the documented sample code did and it worked:
PushService _push = new PushService();
_push.Events.OnNotificationSendFailure += new ChannelEvents.NotificationSendFailureDelegate(Events_OnNotificationSendFailure);
_push.Events.OnNotificationSent += new ChannelEvents.NotificationSentDelegate(Events_OnNotificationSent);
var cert = File.ReadAllBytes(HttpContext.Current.Server.MapPath("..pathtokeyfile.p12"));
_push.StartApplePushService(new ApplePushChannelSettings(false, cert, "certpwd"));
AppleNotification notification = NotificationFactory.Apple()
.ForDeviceToken(deviceToken)
.WithAlert(message)
.WithSound("default")
.WithBadge(badge);
_push.QueueNotification(notification);
_push.StopAllServices(true);
Issue #1:
This works perfectly and I see the notification pop up on the iPhone. However, since it's called a Push Service, I assumed it would behave like a service - meaning, I instantiate it and call _push.StartApplePushService() within a Windows service perhaps. And I thought to actually queue up my notifications, I could do this on the front-end (admin app, let's say):
PushService push = new PushService();
AppleNotification notification = NotificationFactory.Apple()
.ForDeviceToken(deviceToken)
.WithAlert(message)
.WithSound("default")
.WithBadge(badge);
push.QueueNotification(notification);
Obviously (and like I already said), it didn't work - the last line kept throwing a null reference exception.
I'm having trouble finding any other kind of documentation that would show how to set this up in a service/client manner (and not just call everything at once). Is it possible or am I missing the point of how PushSharp should be utilized?
Issue #2:
Also, I can't seem to find a way to target many device tokens at once, without looping through them and queuing up notifications one at a time. Is that the only way or am I missing something here as well?
Thanks in advance.
#baramuse explained it all, if you wish to see a service "processor" you can browse through my solution on https://github.com/vmandic/DevUG-PushSharp where I've implemented the workflow you seek for, i.e. a win service, win processor or even a web api ad hoc processor using the same core processor.
From what I've read and how I'm using it, the 'Service' keyword may have mislead you...
It is a service in a way that you configure it once and start it.
From this point, it will wait for you to push new notifications inside its queue system and it will raise events as soon as something happens (delivery report, delivery error...). It is asynchronous and you can push (=queue) 10000 notifications and wait for the results to come back later using the event handlers.
But still it's a regular object instance you will have to create and access as a regular one. It doesn't expose any "outside listener" (http/tcp/ipc connection for example), you will have to build that.
In my project I created a small selfhosted webservice (relying on ServiceStack) that takes care about the configuration and instance lifetime while only exposing the SendNotification function.
And about the Issue #2, there indeed isn't any "batch queue" but as the queue function returns straight away (enqueue and push later) it's just a matter of a looping into your device tokens list...
public void QueueNotification(Notification notification)
{
if (this.cancelTokenSource.IsCancellationRequested)
{
Events.RaiseChannelException(new ObjectDisposedException("Service", "Service has already been signaled to stop"), this.Platform, notification);
return;
}
notification.EnqueuedTimestamp = DateTime.UtcNow;
queuedNotifications.Enqueue(notification);
}

Categories