Friday, March 2, 2012

Automatically dismiss "App X Would like to Use Your Current Location" dialogs - easy?

tl;dr: Can a alert view shown by the framework (Core Location, …) automatically be dismissed by sending the appropriate touch events to the "OK"-button? Answer: No, not so easy. Want to know why? Read the whole thing.

Every iPhone user out there has probably seen the dialog below (in one way or the other):
Screen Shot 2012 03 02 at 1 28 18 PM
If an app wants to use the current location of an iPhone it has to get the users permission first. This is enforced by a so called "alert view" that is shown automatically by the framework once you (as a developer) try to use Core Location to get the current location of an iPhone. The alert view shown above has two options: "OK" which allows the app to use the current location and "Don't Allow" which is the opposite.
I always wondered if it is possible to automatically dismiss an alert view like this by simulating a click on the "OK"-button. It should be pretty straight forward because a alert view is an instance of UIAlertView which inherits from UIView. What a developer could do, once a alert view like this is shown by the framework automatically is this:
  • find the root view of the app
  • go through the whole view hierarchy recursively and try to find the instance of UIAlertView
  • suppose the "OK"-button on the UIAlertView is just another UIView (or UIButton) then it has to respond to touch events (UITouch, UIEvent)
  • create a "touch up inside" event and send it to the "OK"-button
  • the alert view should be dismissed and your app could use the current location without the users consent
A few days ago I tried to find out if it is really that easy. To make it short: It is not that easy.

Here is why

I believe that the alert view is contained in another process and so there is no way I know of that lets you access the view hierarchy of another process since they don't share the same address space.

How?

I wrote a sample application that registers an object as an observer at the default notification center. As name and object parameter I simply pass nil which means that my notification handler wants to receive every notification of the default notification center no matter who sent the notification and no matter how the notification is called:

[[NSNotificationCenter defaultCenter] addObserverForName:nil 
                                                  object:nil
                                                   queue:nil
                                              usingBlock:^(NSNotification *note) {
     NSLog(@"%@", note.name);
}];


The sample app then tries to access the current location and as soon the alert view pops up the sample app receives a notification saying that it will resign the active state. This does not proof that the alert view is shown by another process because an application usually resigns the active state because of two reasons:
An application is active when it is receiving events. An active application can be said to have focus. It gains focus after being launched, loses focus when an overlay window pops up or when the device is locked, and gains focus when the device is unlocked. ( found in the documentation about UIApplication)
So I turned on Instruments and made a few heapshots and analyzed the stack trace. Lets have a look:
Screen Shot 2012 03 02 at 2 37 25 PM
The -[SISViewController start:] method is the one requesting the current location. Then you see a few CL-calls and then three XPC function calls. XPC is Apples new inter process communication library. So clearly there is some kind of inter process communication going on. This may be the communication with the Core Location Deamon. More importantly I haven't seen a hint in the stacktraces that suggest that a overlay window or a view is created in the address space of the app.
To be clear: I have not found any evidence that suggests that the alert view is in the address space of another process either. Never the less what I found lets me believe exactly that and I think this would be a wise decision. I will try to find absolute proof by using more sophisticated reverse engineering techniques and then I will report back.

Saturday, November 12, 2011

If you need a good designer...

I have worked with a lot of designers over the last couple of years. Some of them did a fantastic job and I happily paid good money for their work. But in my experience designers are highly "volatile" - like gas. What do I mean by that?

Me to Designer: Are you available for design work?
Designer: Yes. Sure.

Me explains everything in great detail.

Designer: No problem. I will do it.

-- 2 Weeks later --

Me to Designer: Hello.

-- No response. 2 Weeks later ---


Me to Designer: Hello - are you there?

-- and so on --

All this is over. I found a really good designer. He is friendly. Very creative. Motivated. Smart. Open minded. Loyal. And most importantly: Not like any gas I know. :)

Thank you Tomas Bartko.


Saturday, October 15, 2011

Status Report: Flashcards for iPad

I just wanted to let you know that I am heavily working on Flashcards for iPad and that you can expect something usable at the end of this year. However I have bad news for everyone who is using Flashcards today:

Flashcards for iPad won't sync with Flashcards for Mac from day one.

Yeah. Its a simple as that and here is why:

In order to make Flashcards possible on the iPad I had to remove a lot of features from the original Flashcards application and replace them with something more or less equivalent. These minor and major differences make the data formats incompatible. Syncing would lead to corrupt data and or would be indefinitely complex to implement. Take rich text editing with inline images as an example. That is absolutely no problem on the Mac. On the iPad this is a major problem. Rich text editing is possible in theory - but not with inline images and not with that kind of layout I have in mind. You can't even read and convert RTFD with the iOS SDK with a reasonable amount of effort.

So what is the plan?

Here is comes: I will release Flashcards for iPad sometime next year. Then I will begin wot work on the next major version of Flashcards for Mac. The next major version will be stripped down and rearchitectured from the group up. At the same time this will enable iCloud syncing. You won't loose any data.

But here is something you may be interested in: With the release of Flashcards for iPad I will also release a minor update for Flashcards for Mac which will be able to export all of your cards and decks to your iPad - once. Then you have to live without syncing for a few months and then everything should be fine again.

Please let me know if you have any problems with this plan. I thought about many alternatives but if you think you have a better solution in mind please let me know.

Ah - and here are two screenshots that show the current status of Flashcards for iPad:



Tuesday, October 11, 2011

Flashcards data loss

The latest Flashcards update has a bug which causes your data to disappear. I am very sorry that this happened. The good thing is that you data is not lost. You can "restore" it by executing the following steps:
  • Close Flashcards
  • Use Spotlight to find an application called "Terminal"
Find Termina with Spotlight
  • Launch Terminal- Paste in the following text:
cp ~/Library/Application\ Support/Ebbinghaus3/Ebbinghaus3.sql \
 ~/Library/Flashcards/Flashcards.sqlite
Screen Shot 2011 10 11 at 9 07 12 AM
  • Press enter- Restart Flashcards
If you need any additional assistance please send an email to support@christian-kienle.de.

Update: A fix has already been submitted to Apple a few days ago but Flashcards is still waiting for review. I will keep you posted.


Saturday, September 3, 2011

Privacy issues with PDFs created using Preview.app

I just found a small privacy issue affecting Preview.app. If you wanna see a demonstration simply watch the video below. I am making this issue public so that every user can find out about it and is able to prevent bad things from happening with their (private) data. In addition to that I have already reported this issue to Apple. What do you think about this?


Download the video

You can add you comment here and/or ping me on Twitter. :)


Saturday, June 18, 2011

My applications and the iCloud

My good friend Matthias from Eternal Storms Software wrote about the impact that iCloud might have on his applications. Since I found his post very interesting (from the standpoint of a devoted user of one of his products and from the standpoint of a developer myself) I will summarize my thoughts about iCloud and how my apps might use iCloud in the future.
 NewImage.jpg

What does iCloud mean for Flashcards?

Flashcards is a flash-card application which is only available for Mac OS X. Wouldn't it be great to have your flash-cards available on all of your Macs? In a previous blog post I showed you how to do this by using Flashcards in combination with Dropbox. This works quite well and it will work well for the current version of Flashcards. I haven't announced my plans for the next major version of Flashcards yet - well up until now: The next version of Flashcards will be a complete rewrite and it will be available as an iPad and Mac app from the beginning. This makes the need for a perfect syncing solution even more obvious and Dropbox won't be good enough. iCloud seems to be the perfect fit for the next major version of Flashcards. Maybe it will be possible to use iCloud to publicly share your flash-cards with your friends.

NewImage.jpg

What does iCloud mean for Drops?

Drops is the ultimate tool for uploading files. At the moment files can only be uploads via FTP and require you to have some kind of FTP server at hand. I think it would be great to use iClouds storage capabilities to make files publicly available. I don't know if that is possible with iCloud. So we will see.

Audio Extractor - Regular Application Icon (256x256) copy.png

What does iCloud mean for Audio Extractor?

With Audio Extractor you simply drop your video files on a drop zone, get something to drink, relax and a few minutes/hours later (depending on the video's size) you can start syncing the audio files onto your iPod, iPhone and iPad. Wouldn't it be great if there was an option to send it to iCloud so that you have the audio file available on all of your devices?
I think that iCloud will make so many apps work even better - including my own and I can't wait to get my hands on the iCloud SDK.

Monday, May 30, 2011

How to sync your flash-cards between multiple Macs

I am a developer and I try to sell my applications the right way. What do I mean by that? If you buy one of my applications you can install and use them on as many Macs you like. You pay for the app once and then you can use it everywhere. Other developers don't like that and take action to enforce this policy. But what do customers do when you allow them to use your application everywhere? Well, they do. Especially in the case of my application Flashcards (a flash-cards application for OS X) my "liberal" policy raises a problem: Flashcards has no built in sync functionality but people would like to work with the same data everywhere. I will now explain how to enable sync in Flashcards although Flashcards has no built in sync functionality. The process I am describing can be applied to a lot of other applications as well (at your own risk of course). So let's get started.

1. Go to Dropbox.com sign up. If you already have a Dropbox account you can of course skip this step.

Screen shot 2011-05-30 at 13.06.26 .png

2. Open the Finder and go to Libary - Application Support. This folder contains a lot of folders - usually you will find a folder for each application you are using. An application typically stores user data inside its application support folder. Note: If you don't find the application folder in Application Support navigate back to the Library folder. Some applications prefer to have their folder located there.

3. In the case of Flashcards open the folder called Ebbinghaus3. The folder is called Ebbinghaus3 and not Flashcards because a few months ago Ebbinghaus was renamed to Flashcards.

Screen shot 2011-05-30 at 13.08.26 .png

4. Move the file Ebbinghaus3.sql to your Dropbox folder.

5. Open the Terminal and type in the following commands:

$ cd "Library/Application Support/Ebbinghaus3"/
$ ln -s ~/Dropbox/Ebbinghaus3.sql Ebbinghaus3.sql

Screen shot 2011-05-30 at 13.11.33 .png

6. The above command creates a link called Ebbinghaus3.sql which points to the real Ebbinghaus3.sql file which is now located in your Dropbox folder.

7. Perform step 4 and 5 on every Mac that you own.

From now on every time you hit command + s in Flashcards the data is stored in the Dropbox folder and gets synced with your other Macs.

Have fun!