Thursday, August 11, 2011

Change apple push notification view button text


We can not change the text of cancel button, but the view button text can be changed.
The payload dictionary has a field "action-loc-key", which takes the alternate text for view button.

The payload dictionary can look like,
{
    "aps": {
        "alert": {
            "body": "Bob wants to play poker",
            "action-loc-key": "PLAY"
        },
        "badge": 5,
        
    },
    "acme1": "bar",
    "acme2": [
        "bang",
        "whiz"
    ]
}

Here the text "Bob wants to play poker" will be the body of alert. and there will "cancel" and "PLAY". Here button text view will be replaced by "PLAY".

For more details on this visit apple reference document here.


Wednesday, August 10, 2011

method list in alphabetical order in xcode 4


There was an option in Xcode-3x in preference with a check box to enable or disable the alphabetical listing of methods, as seen in below picture:

(Xcode3.x option)



In Xcode-4x they have removed this option.
To list the methods alphabetically press and click on the level in the path menu, as in below picture:

(Xcode4.x, +click)


Personally I liked the new feature in Xcode4, as we can list the methods alphabetically or sequentially whenever we want unlike Xcode3 where we had to stick with the option selected in settings tab.

Tuesday, August 9, 2011

Displaying map in Facebook feed in iOS


Sharing images on Facebook feeds is desirable most of the times and can be accomplished by using the attachments in the params dictionary.

I went on a problem to post a Facebook feed that shares users current location as static map image.

The options available was to use a static image from google and use the url as value for 'picture' key in feeds parameters.
But, doing this didn't work. It didn't showed any image on the wall.

If you have a server that can cache and provide you the direct url of the static map image (generated by Microsoft Bing Map or Google Map), you can use that url for the feed purpose.

But, since I didn't had any, I had no option but to see for workarounds.

Searching for the solutions, certainly I found that Foursquare application does share the users location in feed. This foursquare proxy server url returns the static image of size 100x100 from Microsoft Bing Map. You can change the lat/long value in the url and get the desired map for your location.

It uses its proxy servers to generate and handle the map images.

The url for image is of below format,
https://foursquare.com/mapproxy/18.5163333/73.9299163/map.png

Its implementation code can look like below,


    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   kFacebookAppId, @"app_id",
                                   @"http://developers.facebook.com/docs/reference/dialogs/", @"link",
                                   @"https://foursquare.com/mapproxy/18.5163333/73.9299163/map.png", @"picture",
                                   @"Facebook Dialogs", @"name",
                                   @"Reference Documentation", @"caption",
                                   @"Dialogs provide a simple, consistent interface for apps to interact with users.", @"description",
                                   @"Facebook Dialogs are so easy!"@"message",
                                   nil];
    
    [facebook dialog:@"feed" andParams:params andDelegate:self];


Thanks and hope this helps.

Tuesday, August 2, 2011

How to disable Facebook Single Sign On (SSO)


Single Sign On is the desirable feature in almost all applications supporting Facebook.
However, if you tend to a scenario where you do not want this SSO feature, you can
omit the feature in a simple single step without removing any of your code during 
implementation of SSO.

To get away from SSO open Facebook.m file and replace method

- (void)authorize:(NSArray *)permissions
         delegate:(id<FBSessionDelegate>)delegate {

  [_permissions release];
  _permissions = [permissions retain];

  _sessionDelegate = delegate;

  [self authorizeWithFBAppAuth:YES safariAuth:YES];
}

with

- (void)authorize:(NSArray *)permissions
         delegate:(id<FBSessionDelegate>)delegate {

  [_permissions release];
  _permissions = [permissions retain];

  _sessionDelegate = delegate;
    [self authorizeWithFBAppAuth:NO safariAuth:NO];
}

In SSO implementation the method "authorizeWithFBAppAuth" takes parameter as "YES", which indicates Facebook to whether authorize from native Facebook application or from native Safari application.
Supplying the parameter  as "NO" signifies not to open any other application for user authentication. And the application shows its authentication dialogue within application.

Thats all you need to do, and the Facebook authentication dialogue opens within your application.