WinRT live tile badge update - windows-8

I am currently working on a feed reader app in HTML5/JavaScript and I have a problem with live tiles.
I have a live tile that is updating periodically by querying a web service that is returning the latest 3 articles from a blog.
The live tile works as expected, but I want to create a badge notification that will display the unread articles.
The way I have thought to do this is to see if a tile updates and then increment the number from the badge notification. When the user launches the app, the badge will be cleared.
I use the following lines of code:
var notifications = Windows.UI.Notifications;
var polledUri = new Windows.Foundation.Uri("http://my_url/feed.php");
var recurrence = notifications.PeriodicUpdateRecurrence.halfHour;
var tileUpdater = notifications.TileUpdateManager.createTileUpdaterForApplication()
tileUpdater.startPeriodicUpdate(polledUri, recurrence);
This creates the live tile that updates every half an hour. My problem is: I want to create a badge update every time the PeriodicUpdate takes place. I use the following code:
var badgeType = notifications.BadgeTemplateType.badgeNumber;
var badgeXml = notifications.BadgeUpdateManager.getTemplateContent(badgeType);
var badgeAttributes = badgeXml.getElementsByTagName("badge");
var tileUpdater = notifications.TileUpdateManager.createTileUpdaterForApplication()
tileUpdater.startPeriodicUpdate(polledUri, recurrence);
// this is where my problem is
// if (tileUpdater.update() == true) -> This line is not correct: how can I catch the update event?
//badgeAttributes[0].setAttribute("value", currentValue + 1);
var badgeNotification = new notifications.BadgeNotification(badgeXml);
notifications.BadgeUpdateManager.createBadgeUpdaterForApplication().update(badgeNotification);
I want to catch the update event of that tileUpdater.startPeriodicUpdate function and increment the value of the badge. How can I do that? I have searched everywhere and I could not find an answer.
I appreciate your help.
Julian Atanasoae

Even if you could detect that the periodic tile update has occurred (I'm pretty sure you cannot), it will occur most of the time when your app is NOT running. As a result, the code you have to set the badge update via a "local notification" won't execute. In fact, the badge would only update when the app is in the foreground AND a periodic notification hits (which isn't all that interesting, because with your app in the foreground you're not seeing the tile anyway!).
It sounds like you want to track the number of times the tile was updated by showing that in the badge? (Note that will work only up to 99, the max badge number)
I'd say use a periodic notification for the badge too, and the URL endpoint for that periodic update could be a service that accepts a query string argument uniquely identifying the client. Then your service would generate the correct badge notification for that client, by incrementing a client-specific value that's it's maintaining server side.
Even with this though, you'll have two periodic notifications occurring, one for the tile and one for the badge, and while you can schedule them for the same interval, there's still a potential skew in when they arrive, up to 15 minutes from the desired time.

There are 2 solutions to this problem:
1) I create a periodic notification for a badge update and I store GUIDs for each client on a web service. This solution would work for apps that are not heavily used (under 2000 users), because the XML file would get too big and the web service would have to increment a lot of values for each client.
2) I create a background task with a timer and I check for updates every 15 minutes or so.
Julian

Related

ArrowDB - how to get event listener of a chat sent to group?

I'm developing a real time chat app using Titanium Appcelerator. I have everything working with ArrowDB and one user can send another user a message through a group.
https://docs.appcelerator.com/arrowdb/latest/#!/api/Chats
However there doesn't seem to be a method or listener to identify when a new message has been sent to the group.
What I'd like to see is when the other user is typing, and as soon as the message is sent it bubbles up on the recipients chat window. Exactly like how iMessage works.
The only way I can pull new messages from the group to the local users device is to have a refresh button or to use a setInterval with a function call to refresh the messages.
obviously this is not a great way to handle the situation as with a few hundred users every month this would make for hundreds of thousands of api calls and probably not good for device performance.
Does anyone have any ideas how to get real time chat working? Is there a method or event listener I am missing that isn't document?
Push notifications only work while the app is in the background, so this is not an option unfortunately.

IOS Track User Location Map kit

How i can track user location using CoreLocation and MapKit? I place a point on the map. When the application is minimized to check whether the user has not reached the destination. If you reached to withdraw the notification.
Allow your application to run in background
In background, start your get geolocation thread active to get current location (on timely basis, after each 10 secs)
If the results gets approx. equal value (for ex.: 2 km. radius) to your location, then throw a local notification from that app.
To do all this, you will surely find documentation over web, topics are:
Allow your app to run in background
Fetch user's current location (Start this thread in background delegate method)
Match location
Fire local notification
These are the base flow points, hope this will help you for initial start up.

Creating a Metro app which updates itself Periodically and not placed in lock screen

As mentioned here:
It seems that a background task will only run using a TimeTrigger if the user has placed your app on the lock screen.
So, how can I create a Calendar like app without background task? I mean an app which:
updates its tile Periodically (e.g. once a day)?
updates its tile even when it's not running?
You should create a maintenance trigger. These triggers will only fire once every two hours and will only fire if the machine is on AC power. When your trigger runs, you could look for upcoming appointments and create scheduled toast notifications.
var scheduledToast = new Windows.UI.Notifications.ScheduledToastNotification(toastXml, startTime);
You could update the tile as well with a ScheduledTileNotifcation() call. Unfortunately, I don't think there is a way to remove a notification so if the user deletes an appointment prior to the scheduled notification, I don't think you can remove it. I'm looking deeper into that and will comment here if I find an answer.
However, I would think for a calendar app you would want it to use a TimeTrigger and be placed on the lock screen since I would want to receive appointment reminders at any time and regardless of being plugged in or not.
Is there a reason you do not want to use the TimeTrigger?
You can schedule periodic updates of an application's tile without being on the start screen. See this article for Notification Delivery methods. Then, once the app is launched, you could update the calendar in general.

HTML5 video with seamless loop within video

I am programming an interactive video (kind of game) where the user make actions on a side panel and actions happens in the video.
For a part, the video is waiting for user action on the panel, so it has to loop until the action has been launch by the user.
So at 15 seconds, I get back to 11 seconds as long as the user has not made the action, video is designed to be a perfect loop.
My loop is working, but the problem is thats it's not seamless. At 15 seconds, it stops for like a second, and then starts back at 11 seconds. Is there a way to make it work seamless?
I am using VideoJS. Here is my code:
var video_decor = _V_("video_decor");
video_decor.addEvent("timeupdate", function(){
var whereYouAt = video_decor.currentTime();
console.log(whereYouAt);
if(whereYouAt > 15){
video_decor.currentTime(11);
}
});
The easiest way to do a seamless loop is by using a full length video and waiting for the 'ended' event to go back to the beginning. That tends to be pretty smooth, so if you can make that happen some how that'd be best.
Taking a sub-section of the video and looping it is difficult, because browsers don't trigger the 'timeupdate' event every millisecond, and it would be really inefficient to do so. They instead trigger timeupdate every 15 (Chrome/Safari) or 250 (Firefox) milliseconds, so that's your margin of error. You could potentially create your own timer (setInterval) for a smaller interval and check the time manually, but that could put a heavy load on the browser.

Updating application icon Badge in iPhone 3.0, when application is not running

I have an application, which lists number of IM sent by any of my friend using my application. And application icon show number of unread IMs to me. If my application is running in foreground, I can update badge by calling web service every 1 minute which will return number of unread IMs. Suppose, if the person is using iPhone3.0 and application is not running, how can i update the badge? Push notification without alert, but with just number of unread IMs as badge number will work?
Please advice, Thank you.
Yes if the user enables push notifications and allowes it for your app then you can use them to just adjust the badge counter.
At last, we found the problem, the problem is passing badge parameter as string in JSON payload, Now we are sending it as number, so even when the application is in background, badge getting set properly.
Thank you for your all help.