Saturday, July 14, 2007

OK, I admit it after posting about cross browser mobile AJAX I ran into a BIG problem,

It seems that my mobile web portal was running out of steam processing large RSS feeds in Javascript to display on Pocket Internet Explorer.

In addition, Apple Safari seemed to suffer the same issue. (?!?#*! )

So I'm pleased to announce I've solved the problem and here are the results (or see for yourself at www.binaryrefinery.com/mobile )

image

Windows Mobile 5

 

image

I.E 7

 

image

Apple Safari (closet I've got to an iPhone)

 

So how did I get this working?   We'll I wrote a small scheduled task that runs periodically and saves on my web-server a cut down (last n articles) version of my RSS feed.   The mobile portal uses this cut down feed to display rather than the full RSS>  Here's the source of the command line driven schedule task.  I've called it RSS Cutter -

 

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
using System.Xml;

namespace RSSCutter
{
  static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("RSSCutter <url of feed> <no of articles> <output path>");
                return;
            }
            int no_of_articles = 1;
            try
            {
                no_of_articles = Convert.ToInt32(args[1]);
            }
            catch
            {
            }
            RSSCutter r = new RSSCutter(args[0], no_of_articles, args[2]);
        }
    public class RSSCutter
    {
        public RSSCutter(string url, int no_of_articles, string outputpath)
        {
            WebRequest req = WebRequest.Create(url);
            WebResponse result = req.GetResponse();
            Stream receivestream = result.GetResponseStream();
           
            XmlDocument x = new XmlDocument();
            try
            {
                x.Load(receivestream);
                result.Close();
                receivestream.Close();
            }
            catch
            {

            }
            XmlNodeList nodes = x.GetElementsByTagName("item");
            if (nodes.Count == 0) return;

            int intcount = 0;
            foreach (XmlNode n in nodes)
            {
               if (intcount>no_of_articles) n.RemoveAll();
                intcount++;
               
            }

            x.Save(outputpath);
    
        }
    }
}
Technorati tags: ,
Saturday, July 14, 2007 9:53:15 PM UTC  #    Comments [0]  | 
Monday, July 09, 2007

So after detecting my first iPhone connect to my Blog,   I wondered whether the Mobile AJAX code that I wrote for Windows Mobile would work for other browsers.See  -

http://www.binaryrefinery.com/main/default,date,2007-04-23.aspx#a7c1ae14c-edd5-4306-b6e1-cf70952330ba

 

So, I decided to download the Apple Safari web browser for windows.   I thought that Safari would show up pretty well how my mobile Blog would appear on an iPhone.  Surprise, surprise my mobile AJAX blog just didn't load.  Safari can be obtained here -

http://www.apple.com/safari/download/

 

This was clearly due to the creation of Active X objects in the mobile page, like -

g_request= new ActiveXObject("Microsoft.XMLHTTP");

 

Anyhow following the Safari web developers guide I put in some basic browser detection, I won't bore you with all the code.   But if you interested have a look at the results at -

http://www.binaryrefinery.com/mobile

(then do a view source on the page)

Technorati tags: , ,
Monday, July 09, 2007 8:21:34 PM UTC  #    Comments [0]  | 
Thursday, July 05, 2007

I've needed to expand my automatic redirection script to direct iPhone users to mobile web pages in the same way that I do for Windows Mobile/WAP type devices.

Following Apple's guidelines at  -

http://developer.apple.com/iphone/designingcontent.html

I expanded my automatic redirection ASP.NET page that I blogged about awhile back to include this feature.  Previous post at -   

http://www.binaryrefinery.com/main/default,month,2007-03.aspx#a48c1e6c7-573c-4f68-993e-00aa6f600b7f

Its does the job.   + I am pleased to see that today I have my first iPhone user find my Blog,  I wonder what they think?

 

ASP.NET C# source below -

 

<%@ Page Language="C#" Trace="false" %>

<SCRIPT LANGUAGE="C#" RUNAT=SERVER>

    protected void Page_Load(Object sender, EventArgs e)
    {
        System.Web.Mobile.MobileCapabilities cur = (System.Web.Mobile.MobileCapabilities) Request.Browser;

        

        // this block of code is to detect if users are running Pocket PC 2003/CE or iPhone
        bool isce=false;
        bool isiphone=false;

        try    {
            isce = (Request.UserAgent.IndexOf("Windows CE")!=-1);
            isiphone = (Request.UserAgent.IndexOf("iPhone;")!=-1);
        }
        catch
        {

        }
    
        if (cur.IsMobileDevice||isce||isiphone)
        {                
            Response.Redirect("mobile");  // MOBILE PAGE
        }
        else
        {
            Response.Redirect("main"); // NORMAL PAGE
            
        }
        
        
    }

</SCRIPT>
Thursday, July 05, 2007 3:00:51 PM UTC  #    Comments [0]  | 

Theme design by Jelle Druyts

Pick a theme: