Wednesday, June 10, 2009

iPhone ad hoc provisioning profiles

In trying to develop for the iPhone you've got to create provisioning profiles, and this was proving to be more complicated than I thought. Going through the directions (creating cert, creating app id, creating provisioning profile) wasn't working. I'd either get an error when trying to sync, or even have trouble creating the app in the first place. Here's what I did to solve it:

Make sure your default keychain is login
Clear off all the certs and start fresh.
Make sure your you are added to the team, and your device is added
Create the initial cert according to Apple's directions, submit it and approve the cert. (do this for both the development and distribution tabs under certificates
Download the two certs and install them.
Download the WWDR intermediate cert and install it.
Create the app id, I used com.overlandagency.appname for the bundle identifier
Create a distribution provisioning profile picking the app id, make sure you select your device
Download the provisioning profile
In Xcode right click on the top item in Groups & Files and select Get info
Under the build tab, under code signing make sure the code signing identity and any iphone OS device have "iPhone Distribution: your name" set
Right click the app under targets (in groups & files) make sure the Code signing entitlements (under code signing) is set to the plist file (you've created according to apple's instructions)
Click the properties tab and make sure the identifier is correct (in this case com.overlandagency.appname)
Click clean all targets in Xcode (this fixed many problems)
Click build, right click on the .app file in products and pick reveal in finder

I ran into problems at one point because my mac had weirdly set itself to the wrong time so I was getting a CSSMERR_TP_CERT_NOT_VALID_YET error, that refused to clear up. Even though I fixed this problem, I couldn't even build at this point, but then making sure I clicked "Clean all targets" fixed this problem, and could have been half of what was going on with issues I was having before.

Labels: , , , , , , ,

Thursday, May 28, 2009

Reading excel files from .NET

It is pretty easy to create excel files on the fly from .NET

Using the office automation stuff to read from excel files was always a pain. Here is a way to avoid that.

The connection string is just something like this:

String connString = @"Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + Server.MapPath("Coupon Report Example.xls") + ";Extended Properties=Excel 8.0";

And you'd read from it with just a "SELECT * FROM [Sheet1$]"

If the sheet is named something else, you can just use the following to get the correct sheet name. http://www.codeproject.com/KB/aspnet/getsheetnames.aspx

Labels: , , , , ,

Thursday, February 26, 2009

Styling buttons in safari with ease

I've always hated how Safari would style buttons (dorky rounded) instead of how everyone else would render them. I found a site saying that having <button> tags would avoid this (over <input> tags), but .NET renders <asp.Button as a input.

There is a way to get .NET to render how you'd like, and it seems to work, click here

Labels: , , , , , , ,

Wednesday, February 11, 2009

Ajax steps in browser history in .NET 3.5

.NET 3.5 has new functionality in the scriptmanager object to handle putting ajax "steps" in the browser history.

By setting EnableHistory="True" you can add items to the history in your codebehind, and respond to them with OnNavigate (in scriptmanager)

The great thing about it is you can put in history items whenever you choose and respond to them how you would like, so the process of stepping back can make sense.

Look at the code in this zip (with both version for plain .NET and using Telerik controls)
Ajaxhistory.zip

Labels: , , , , , , , ,

Friday, February 06, 2009

Font embedding

Ben R who is doing a site for us showed me how to embed fonts. This can work directly for Firefox (3.1+) and Safari and with a little work for all versions of IE.

Click here to see a page with embedded fonts (note, if you're using FF 3.0 and below you won't see anything). View source to see how I did it.


Here is the tool you have to use for IE to create the embedded font (which is tied to the domain), it was pretty crashy on Vista, but since it was written many years ago that isn't a big surprise. Supposedly this will work for versions of IE way back, I did have an issue with warning messages (just warning about temp use of a font) on a locked down version of IE6 on a server.

Labels: , , , , ,

Thursday, February 05, 2009

Pretty tables

I was wondering if I could make tables that were entered via a CMS have special formatting (alternating line color, custom header) without making the user entering the table via the CMS have to tag the rows or cells with classes. And yes, Nate, these really are tables...

So I thought I could use regular expressions to parse the content block and pull out tables, parse through the lines of the table and automatically set the class of the tr. I was able to come up with some code to do this, and it seems to work pretty well. Remember to put "using System.Text.RegularExpressions;" at the top of your file.


prettytable.txt

An example? This was a table with no formatting:

Labels: , , , , , , , , ,

Friday, January 23, 2009

iPhone/mobile view of website

I built in an iPhone/mobile view to our CMS, but wanted to have the content fill the screen on the phone when you went to it.

<meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>

This will present the content (if the content is formatted to be 320px wide) to fill the screen of the phone's browser. Check out http://www.overlandagency.com

Labels: , , , ,

Testing for mobile browser

I've been looking for a .net version of some code to test to see if the user is viewing the site with a mobile browser. Here's what I came up with cobbled together from several references:

public bool isMobileBrowser()
{
string strMKey = null;

string strHttpAccept = null;
string strHttpUserAgent = null;

strHttpAccept = Request.ServerVariables["HTTP_ACCEPT"].ToLower();

strHttpUserAgent = Request.ServerVariables["HTTP_USER_AGENT"].ToLower();

// User Agent is windows but not windows mobile?
if ((strHttpUserAgent.IndexOf("windows") >= 0) && !(strHttpUserAgent.IndexOf("windows ce") >= 0))
{
return false;
}

// User agent matches one of these keywords?
string[] Key = new string[] { "up.browser", "up.link", "windows ce", "iemobile", "mini", "mmp", "symbian", "midp", "wap", "phone", "pocket", "mobile", "pda", "psp", "iphone" };

for (int i = 0; i < Key.Length; i++)
{
if (strHttpUserAgent.IndexOf(Key[i]) >= 0)
{
return true;
}
}

if ((strHttpAccept.IndexOf("text/vnd.wap.wml") >= 0) || (strHttpAccept.IndexOf("application/vnd.wap.xhtml+xml") >= 0))
{
return true;
}

if ((Request.ServerVariables["HTTP_X_WAP_PROFILE"] != null) && (Request.ServerVariables["HTTP_X_WAP_PROFILE"].ToString() != ""))
{
return true;
}

if ((Request.ServerVariables["HTTP_PROFILE"] != null) && (Request.ServerVariables["HTTP_PROFILE"].ToString() != ""))
{
return true;
}

if ((Request.ServerVariables["X-OperaMini-Features"] != null) && (Request.ServerVariables["X-OperaMini-Features"].ToString() != ""))
{
return true;
}

if ((Request.ServerVariables["UA-pixels"] != null) && (Request.ServerVariables["UA-pixels"].ToString() != ""))
{
return true;
}

// Check first four char from strHttpUserAgent
string[] M = new string[] { "acs-", "alav", "alca", "amoi", "audi", "aste", "avan", "benq", "bird", "blac", "blaz", "brew", "cell", "cldc", "cmd-", "dang", "doco", "eric", "hipt", "inno", "ipaq", "java", "jigs", "kddi", "keji", "leno", "lg-c", "lg-d", "lg-g", "lge-", "maui", "maxo", "midp", "mits", "mmef", "mobi", "mot-", "moto", "mwbp", "nec-", "newt", "noki", "opwv", "palm", "pana", "pant", "pdxg", "phil", "play", "pluc", "port", "prox", "qtek", "qwap", "sage", "sams", "sany", "sch-", "sec-", "send", "seri", "sgh-", "shar", "sie-", "siem", "smal", "smar", "sony", "sph-", "symb", "t-mo", "teli", "tim-", "tosh", "treo", "tsm-", "upg1", "upsi", "vk-v", "voda", "wap-", "wapa", "wapi", "wapp", "wapr", "webc", "winw", "xda-", "modu" };

strMKey = strHttpUserAgent.Substring(0, 4).Replace(" ", "-");

for (int i = 0; i <M.Length; i++)
{
if (M[i] == strMKey)
{
return true;
}
}

return false;
}

Labels: , , , ,