views:

60

answers:

0

application is based on facebook authentication & message post on wall after googling ifind some code in this uses NSRegularExpression & NSTextCheckingResult it generate some error becoz this class compatible with ios4 or lator but i using ios3.1 for removing this what i do (i know to resolve this NSString's rangeofstring or substring methods i'm to perform bt i don't know how to do this here is coding ......

-(void)checkForAccessToken:(NSString *)urlString {
    NSError *error;
    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"access_token=(.*)&" options:0 error:&error];
    if (regex != nil) {
        NSTextCheckingResult *firstMatch = [regex firstMatchInString:urlString options:0 range:NSMakeRange(0, [urlString length])];
        if (firstMatch) {
            NSRange accessTokenRange = [firstMatch rangeAtIndex:1];
            NSString *accessToken = [urlString substringWithRange:accessTokenRange];
            accessToken = [accessToken stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            [_delegate accessTokenFound:accessToken];               
        }
    }
}