Thursday, July 10, 2014

iOS Enterprise App Distribution

We have been going through the steps for building an app for iOS Enterprise distribution.  To make it
a little harder, the apps were being built in Xamarin.  However, the steps below works for Xcode too.  We finally conquered all the challenges -- and it wasn't super easy.  Here are a few items to remember for next time:

  • As of iOS 7.1, you must deploy your ipa file to an SSL cert site.
  • You must setup a distribution Provisioning Profile (from an Enterprise subscription).  Once you generate one, download it locally, then right click and "Install".  I had to restart Xcode for it to be recognized.

    With Xamarin, there was only one gotcha: After importing the Provisioning Profile, we had to go to the Project and right-click => Options.  Then go to "iOS Bundle Signing".  From there, we had to make sure the correct Identity was selected and the correct Provisioning Profile.  This was not auto-selected correctly.
  • Additionally, we had to go to iOS IPA Options and check the Build ad-hoc/enterprise package. No other options were filled on that screen.

  • When deployed to the website, when we clicked on the download link, we started receiving the error message:
Unable to Download Application
"Your Application" could not be downloaded at this time.
To fix this, we discovered that the URL that is built into the plist file has to be the full path to the ipa file, such as:

<dict>
<key>kind</key>
<string>software-package</string>
<key>url</key>
<string>https://domain.com/fullpath/AppName.ipa</string>
</dict>


  • Finally, we had to set the mime type correctly.  We were using IIS, so:  Open IIS Manager, right-click on Server(local computer), select "MIME Types" => New.  Then add the following:


.IPA   - application/octet-stream 
.PLIST -  text/plain.

Once all that was corrected, we clicked on the link and auto-magically everything lit up and worked.  It's not super easy, but really flows nicely when it works correctly.

Thursday, June 12, 2014

iOS In-App Purchase Error - “Cannot connect to iTunes Store”

From Macgasm

It's true, In-App Purchases are awesome.  However, setting it up could drive you crazy.  I've personally spent too much time tracking this one “Cannot connect to iTunes Store” error down, so I decided to document the fix here.

If you are trying to do an In-App Purchase you might encounter this error.  It happens just as you send the product in for payment.  For me, its with a line like this:

SKPayment * payment = [SKPayment paymentWithProduct:product];

The weird thing is that the product is found just fine.  So, I know the connection to the iTunes Store is working fine.  However, it won't finalize the purchase.  It throws an error that gives (in my case) one of two errors: 0 or 1003.  You can find this error number by implementing the following (Which is taken from Ray Wenderlich's excellent IPAHelper):

- (void)failedTransaction:(SKPaymentTransaction *)transaction {
    
    NSLog(@"failedTransaction...");
    if (transaction.error.code != SKErrorPaymentCancelled)
    {
        NSLog(@"Transaction error: %@", transaction.error.localizedDescription);
    }
    
    [[SKPaymentQueue defaultQueue] finishTransaction: transaction];

}

So, here is how I got both error codes to go away:

Error 0 - You must:
  1. Make sure you have accepted all the documentation terms and conditions within https://itunesconnect.apple.com.  Check under Contracts, Tax and Banking just to make sure.
  2. Make sure you are using a test user within the iPhone you are testing with.  To do this, go to iTunesConnect => Manage Users.  Then add a new test user.  Finally, on the phone you are developing with, go to Settings and sign out as your current user.  Sign in with the new test user you just made.  This should do it!
or

Error 1003 - This one seems to be a networking problem.  To clear this, I recommend you delete the App from your test device, Clean the project in Xcode, rebuild and re-deploy.

Another thing you should check is that Apple's service is up.  If you hit the following address, and you see no response, it's down.

https://sandbox.itunes.apple.com/verifyReceipt?uo=8&at=11ld4k

Once you get In App Purchases working, its pretty sweet.  Good luck, its worth it!




Wednesday, April 2, 2014

Overheating Apple Time Capsule

I was forced to convert to Apple products a few years ago to allow me to start building iOS Apps. For the most part I've been happy with their computers & mobile devices. One item that has caused me constant problems is the Time Capsule backup unit. As I found out, it looks cool, but runs HOT!

FYI: The TC is a 4th Generation 2TB model

On warmer days, it would lock up and eventually shut down. Of course, it happened at the most inopportune times. Since my office Internet routes through it, not only would my old backups go away, but Internet traffic would be down. When I started to explore what was going on, I found many people complaining about the same thing: an under-performing cooling system.

The Time Capsule seems poorly designed and/or badly constructed. I say that because the internal fan seems to only come on in an overheated situation. It doesn't keep it constantly cool. Additionally, the fan is butted up directly at the wall hard drive, leaving little room for airflow to come out and around the unit.

There are several online mods (here and here), but I decided to implement my own.  This mod combines their ideas, but the fan doesn't sound like a jet engine on takeoff when you get done.

As you can see from the infrared image of the drive, the hottest part seems to be in back, right where the power supply electronics are located.  The components that take line voltage and step it into a stable power supply create a lot of heat.  Often it was hot enough that I couldn't keep my hand pressed on the unit.

Strange enough, the hard drive was relatively cool.  It is located in the lower right quadrant on the infrared image.

The Nitty-Gritty of the Mod

After removing the rubber base with a heat gun, I got access to the bottom aluminum plate.  After removing about 1000 screws, the internals opened up.  Obviously, the unit must be disconnected from power.

After surveying the situation, I removed the fan and snipped the third wire (See pic).  I put it all back together and started up the unit.  With that wire snipped, the fan runs at 100%.  It cools like crazy, but is much too loud.  So, I needed to add resistance to the #1 wire.

I then took it all apart again.  Next, I removed the fan, snipped the #1 (see the arrows in the pic.)  Then I soldiered in two 100 ohm resisters in parallel.  The leads on each resistor are twisted with the duplicate lead on the other resistor putting them in parallel. The two ends of the #1 wire then were stripped and each end was soldiered to each side of the twisted resistors.

The new resistance (which turns in 50 ohms) causes the fan to run at a much lower speed, but still provide adequate cooling.  I finished the electrical job by wrapping the entire resistor assembly with electrical tape.

Next, with a Sharpie I also marked exactly where the fan was located on top of the aluminum plate.  I drilled a pilot hole, then a 1 1/2" diameter hole to get the max amount to air into the unit.

Finally, in putting it all back together, I rotated the fan 90 degrees so that the output of the fan was pointing at the electronic boards (not the hard drive.)  I used electrical tape to ensure the most of the air goes through the electronics and not out the sides (See pic).

To finish it all off, I put rubber feet from Lowe's on the unit to give it about 1" of clearance under the unit.

When I put it all back together two great things happened: first the fan ran at a level that can't be heard unless you put your ear up to the unit.  Second, it cooled the system down to a level it can handle.  The max temperature I could find was 91.4 F.  That's much better than the 120 F I was getting before the mod.




Thanks to my neighbor who works for Axis cameras for loaning me the best IR camera I've ever seen: the Axis Q1910.


Wednesday, December 18, 2013

Removing Hard Returns with a DOS Batch File

This is just a quick post to save a much-queried DOS Batch file. This will delete hard returns from a given input file. Note that it does an append (">>") to the output file, so you will need to delete the output file each time you run this command.

for /f "delims=" %a in (inputfile.txt) do (echo /s|set /p="%a") >> outputfile.txt

Works like a champ!

Thursday, June 6, 2013

How To Forcefully Shutdown a Windows 7/8 Program

I had a question from a customer yesterday on how to shutdown a non-responsive application. Of course, the best way to do it is to close it the normal way, but what do you do if nothing happens?

In Windows 7/8, I recommend these steps:

  1. Open a command prompt by going to your Start button and typing cmd
  2. In the command prompt window type: taskview
    This will list all the processes running on your computer.
  3. Find your application, such as "explorer.exe" in the following image. To the right of the file name is the PID -- such as 1532 in the below example.
  4. Next try this command: killtask /PID NumberFromStep2. For example:
    killtask /PID 1532
    This command will try to gracefully shutdown the process. This probably won't work if just clicking "close" in the application doesn't work. However, its a good thing to try first.
  5. If the application still doesn't shutdown, it's time to use some force: killtask /F /PID NumberFromStep 2. For example:
    killtask /F /PID 1532

At this point one way or the other, that application is not running. If it still shows up when you type taskview, then there is a dependency problem with something else running. A reboot is in order.

Tuesday, May 21, 2013

Restricting Access By Location in IIS

A customer and I were reviewing their web logs and remarking on how many hits were coming in from countries with which they don't even remotely do business. There were several visits each day from China, Russia, Korea, etc. If they were coming to the site, they were either seriously lost or just up to no good.

We decided to restrict access to those folks that just shouldn't be there. Here is how we did it:

First, we are using IIS7. If you are using a Unix flavor, you need to modify your .htaccess file in the /etc directory. If you are on IIS, there is a similar procedure. You will be modifying the following file:

%WinDir%\System32\Inetsrv\Config\applicationHost.config

Open this file on your IIS Server and search for

location path=
until you find the web instance you want to apply these settings to.

Next you want to get this file: http://ip-to-country.webhosting.info/downloads/ip-to-country.csv.zip This file is a list of IP addresses by country code.

The last thing to download is this excellent javascript file built by Kanwaljeet Singla. It parses the ip-to-country file into commands you can use in the applicationHost.config file. Once you have the file, rename it to: ipres.js

When you have everything, put it into a folder and pop open your command prompt and go to that directory. Here are a few interesting commands that Kanwaljeet built in:

 // Generate an "allow" list for USA IP addresses
cscript.exe //nologo ipres.js /f ip-to-country.csv /a USA
 // Generate an "deny" list for China IP addresses
cscript.exe //nologo ipres.js /f ip-to-country.csv /d China

So, here is how I got the website to deny anything but United States IP addresses:

  1. Ran the utility above with the command:
    cscript.exe //nologo ipres.js /f ip-to-country.csv /a USA > usa.txt

    This created a file called usa.txt

  2. Opened usa.txt in notepad and copied the text between
    <ipSecurity allowUnlisted="false">
    and the last "add" entry
  3. Opened the ISS ApplicationHost.config file mentioned above in notepad.
  4. Pasted the entire section into the system.webServer/Security section. I also added a special entry that allows me to access the site locally:
    <add ipAddress="10.0.0.0" subnetMask="255.0.0.0" allowed="true" />
  5. Recycled the Application Pool with that website and voila!
Great credit goes to Kanwaljeet Singla for his cool tool.

Friday, May 10, 2013

SignalR - Microsoft Battles Back

As with many IT leaders (and shareholders), I've been watching Microsoft closely. Will it be able to re-emerge as a winner? Or has Microsoft reached their apogee and all we can expect is decline. To hear the news, Apple/Google/Facebook/etc are the winners.

However, there are a number of Microsoft technologies that are poised to change the computer landscape yet again. The one that has been helping me (and which has incredible potential) is SignalR.

SignalR is all about pushing data from the server to a client. For me, it has been a lifesaver for browser communications (but it can be used in any kind of client.)

Server-initiated communications have always been tough, especially on top of the http protocol, which is primarily client-initiated communications. The SignalR team has done a couple of really smart things:

  • Client agnostic - First they came up with a mechanism that doesn't really matter what client your user is using. It will automatically downgrade its technique to whatever technology is available. For instance, if you are using it within a browser, SignalR will try the following technologies until it finds one that will work with the user's browser:
    • HTML5 Websockets
    • Server Sent Events (EventSource)
    • Forever Frame (Older IE browsers only)
    • Ajax long polling
  • API's - There are a number of SignalR API's that make the job incredibly simple. I have primarily used the Javascript API, but you can incorporate it into almost any .net, c++, Java, etc app.

As they say, anywhere a client polls for information from a server is a good candidate for SignalR to be put in place. So, besides webchat, I've thought about using it for:

  • Server monitoring
  • Game servers / Game cheat monitoring
  • Realtime business dashboards
  • Realtime asset mapping
  • Website social network updating
  • Website widgets (weather, stock, deals, etc)
  • Notifications to your desktop much like Apple realtime notification service

So, if you are looking for server-initiated, real-time communications, I recommend checking it out. I'm working on a demo that I'll post to this article later today.