Storing iCloud Container URL - icloud

Can I store the NSURL returned from:
[[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil]
in the NSUserDefaults (or plist) to enable faster access to the iCloud container when my app starts?
Currently, the above code can take a good few seconds (sometimes 10 seconds plus) to return the container path. This results in a noticeable and annoying lag in loading up the user's data from iCloud as my app waits for the return.
I'm assuming that the NSURL path is exactly the same each time the app is launched and so it should be ok to store it for quick access later.
I have tried this on my own devices and it works fine, I am just wondering if there may be any problems doing this out in the 'wild'.
Ta

That will probably work. But it doesn't solve a problem, it just moves it around. That method blocks like it does because internally it's getting iCloud up and running for your app (which might involve network calls). That's going to happen sooner or later, because it's part of the iCloud setup process for your app. You might avoid that call but you'll hit the delay somewhere else.
The only major gotcha is that the user might log out of iCloud while your app isn't running, or worse, log out of iCloud and in to a different iCloud account. If you save this URL, make sure you also save the value of ubiquityIdentityToken (which you can look up without blocking), and check whether its value has changed at app launch time. Also listen for NSUbiquityIdentityDidChangeNotification and, if it's ever posted, look up the URL again and save the new value.

Related

Offline capabilities when using REST (Firebase)

So I found this here in the Docs:
Every client sharing a Firebase maintains its own internal version of any active data. When data is updated or saved, it is written to this local version of the Firebase. The Firebase client then synchronizes that data with the Firebase servers and with other clients on a 'best-effort' basis.
As a result, all writes to Firebase will trigger local events immediately, before any data has even been written to the server. This means the app will remain responsive regardless of network latency or Internet connectivity.
Once connectivity is reestablished, we'll receive the appropriate set of events so that the client "catches up" with the current server state, without having to write any custom code.
Yeah, I got that going for me, but to be more specific (and I wasn't able to find an answer to that):
I am using the REST-API in a c++-program, which executes a curl-request. Everything is working so far. For the insertion, this is not a big deal. In case of an error, I can easily store the data via redis or something and update them later, but how does reading work?
To give you a scenario:
I made a scanner, which recognizes an ID. After this process, it is inserted (as explained above) into the Firebase. People can also register on a regarding homepage (and insert their ID manually). This will be saved in the Firebase as well. Same node obviously.
Firebase is designed to provide the data from one endpoint to another by accessing the db, which is fine. The user registered on the site and is inserted in the DB. Suddenly, my internet connection went away.
Is there any way to get the last "stack" or "full dataset", which was used, before my connection went away? Is there a way to replicate the DB and queue jobs, which will sync after the connection is re-established?
Disclaimer: I work for Firebase.
The passage you're quoting above specifically refers to the client libraries that we maintain (currently in Objective-C, Java, and JavaScript) - which are pieces of code that we've written that you would run in your app.
In this case, you're specifically not using a client library - you're just hitting our regular REST endpoint, so you won't get any of the benefits. To implement your own client would be a significant undertaking; it's the client code that maintains the internal view of the data, compensates when it's offline, triggers local events, etc.

Volume changes without creating notification for IAudioEndpointVolume

I'm have written a C++ application that is running as a Windows service to limit the volume of a Windows 7 computer. The user can specify different rules for different days and times and the service will smoothly change the volume. To implement this I use the IAudioEndpointVolume interface. In general it works like intended...
However, there exists a strange behavior I cannot explain yet. When switching users the volume suddenly drops but it does not generate a notification as one would expect. What is also strange is that the sliders in the SndVol.exe show the correct value for the volume.
Because of the missing notification my program cannot react to this change and as a result it cannot perform its intend anymore.
I have discovered that the volume will switch back to its correct volume again if I move the volume slider a bit. Of course this generates a notification that will be handled by my service. My service will then force the correct volume.
I don't understand why the volume changes without being visible in SndVol.exe and without creating a notification. Switching back to the first user account does not solve the problem. Even after logging out the volume is still at the wrong level.
As far as I have seen the documentation about the IAudioEndpointVolume interface does not mention anything about different user session.
Any ideas on what might cause this problem or what I could try to fix it?
Your service runs in session 0, the isolated session that prevents malware from exercising shatter attacks. The user's desktop runs in another session, there can be multiple. The WASAPI documentation is silent about exactly how an audio session gets mapped across Windows sessions. You have a very strong hint that it doesn't from the way it behaves.
There are ominous words in the section that talks about grouping parameters. A construct that primarily exists to allow Sndvol to identify processes that share the same volume control. It quotes Explorer as an example, a process that can be started more than once but still has a single volume control. A process that doesn't want to share uses session identifier GUID_NULL to select the default session in IAudioSessionControl::SetGroupingParam() or simply omits the call altogether since that's the default.
And the behavior of Sndvol, it only displays volume controls for the processes that run in the desktop session. You can't see the processes in another desktop session. Giving a very strong hint that audio session GUID_NULL is specific to the session in which it got created.
So quite unlikely that you can find a workaround for it as long as you do this with a service.
Instead, consider running your program as a normal windowless process that runs in the user's desktop session. Getting started by the Run registry key or a Startup folder shortcut or the task scheduler.
Well, after some time I am now quite confident that the volume change is caused by the 3rd party driver we are using. This driver has it's own volume control mechanism. I do not experience the change anymore after just starting the drivers' control GUI. Even after a restart the problem seems to be fixed. However, after some time it gets broken again for a reason I cannot figure out. But this only happened because some security settings prevented the drivers' control GUI to start when logged in as non admin. I fixed this now and expect everything to work now.
Furthermore it looks like that all user sessions share the same volume control. That means if I change the volume with SndVol in one user session the same change happens in the other user session. My service receives notifications for all these changes. So it looks like that I did not receive a notification when switching between users because the change was caused by the driver's control GUI starting when logging in as administrator. But this change happened in the driver, a lower layer, so that Windows is not aware of the change.
The driver we are using is the kX Audio Driver.

Send images when app is tombstoned/closed?

The app I'm currently developing needs to send images and text to a webservice, and so far so good. The app works fine, but the next step is to make it keep sending when the user exits the app or changes to another app.
How do I achieve this?
I've looked at the background agent function, but that doesn't seem to be what I want. I do not want to wait every 30 minutes and then try to send for 25 sec with the periodic agent, and the users will almost never be in the very limiting state that the resource-intensive agent requires (over 90% battery life, must be on wi-fi etc).
Am I missing something obvious here? Only sending pictures and text when the user has the app active is a big down side.
I'm afraid it is not possible to do what you require with the current WP7 OS. The Windows Phone 7 OS has been designed to restrict applications in such as way that the user's security is protected, battery life is prolonged and they have a consistent experience. Allowing any application to execute arbitrary code in the background, without imposing constraints on execution time or duration would allow people to write applications that are extremely resource intensive. This is not good for the end user!
The "periodic" or "resource-intensive" agents, as described on MSDN, are your only options.

Internet Explorer BHO check for multi-instance of site

I'm working on a project for a client. We are building an internal web portal, and for various (mostly political) reasons have ended up building a BHO for IE8. One of the things t does is make sur that only one instance of the portal can be opened at once. It does this by writing a temp file when the portal is opened. Unfortunately this is not optimal as if IE crashes for any reason then the next time the portal is fired up, the user is left staring at an "unauthorised" message until the stale temp file is removed.
So my question is: is there any way within a BHO to see how many times the same url has been loaded? I mean is there some way to get that information directly from IE?
It's actually a little more complicated than that, given that we need to allow popups etc. But this would be a good start.
Thanks for your time.
If you want limit browser instances in the current user session you can use a mutex instead of a file. try acquire the mutex at the startup of the BHO (in the SetSite call) with a reasonable timeout, and release again in the final SetSite call.
If the result is WAIT_OBJECT_0 or WAIT_ABANDONED, there is no other BHO instance holding the mutex, while WAIT_ABANDONED occur when another thread crashed while holding the mutex. If the result is WAIT_TIMEOUT, the mutex is already taken by another BHO instance and you should not let the user to use your web site according to your requirement.
But if I am a determined user I can fire up XP Mode and access the web site from there...

How to download and execute a file every month invisibly to the user?

I need a way to download ( from a server ) and execute a file every month automatically and invisibly to the user.
How can I do that ?
Don't blindly check for updates on a schedule. Instead, check when the user starts your application (every time, or every 10th time, or every 30th day, but only when the app gets used).
Users hate it when an application they aren't running is taking up resources.
As Steve Jessop points out, it may also be good to occasionally check again if the app stays running for a long time.
Installing a "Scheduled Task" is still the way to go, but set it to run manually instead of on a periodic schedule, then your app can trigger it. An app can trigger a task that executes with higher permissions than the app itself (creating the task in the first place requires full admin rights). The task also remembers the last time it ran which is useful for keeping traffic down.
An application that you build as a Windows service will run in the background and can do what you want.
Microsoft Windows services, formerly
known as NT services, enable you to
create long-running executable
applications that run in their own
Windows sessions. These services can
be automatically started when the
computer boots, can be paused and
restarted, and do not show any user
interface. These features make
services ideal for use on a server or
whenever you need long-running
functionality that does not interfere
with other users who are working on
the same computer.
Least intrusive way is just to check when the application starts. (Every time, or every 10th time, or whatever). I know other large apps don't do that, but as a user I really hate it, perceive these apps as "bloat" and avoid when possible. (Example: iTunes). Anything else just clogs up my computer when I'm trying to do something else.
Also, you'd better make sure the code is safe to run; use a digital signature to be sure that the code is really from you. Otherwise you're vulnerable to a man-in-the-middle attack: I could set up an imitation server and send evil code to your users. (Or hack your server and upload evil code to your server for your users to get. Etc. etc.)