Friday, November 1, 2013

encode URL ---- IOS


-(NSString *)encodeURL:(NSString *)urlString
{
    CFStringRef newString = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)urlString, NULLCFSTR("!*'();:@&=+@,/?#[]"), kCFStringEncodingUTF8);
    return (NSString *)CFBridgingRelease(newString);
}

Monday, October 21, 2013

Scroll UITextView to top .--- IOS

 UITextView *YourTextView
  [YourTextView setContentOffset:CGPointMake(0, 0) animated:YES];

Sunday, October 6, 2013

Change TextView font , color etc using HTML -- IOS

NSString *htmlString = @"<html>Lorem  ipsum dolor sit er elit lamet,  <font face=\"verdana\">This is some text!</font>  consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.<h1> Excepteur sint occaecat cupidatat non proident,</h1> sunt in culpa qui <font size=\"2\" color=\"blue\"><b>This is some text!</b></font> officia deserunt mollit anim id est laborum. <b>Nam liber te conscient to factor tum poen legum odioque civiuda</b>ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu <b>fugiat nulla pariatur</b>. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda\n\n Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. <h2>Duis aute irure dolor in reprehenderit</h2> in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa <h3>qui officia</h3> deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda</html>";
   
   
    [YOURTEXTVIEW  setValue:htmlString forKey:@"contentToHTMLString"];


                                        ******************OR****************

1- Create a textfile and add in your project .. dummytext.txt
2- Put all HTML code in that file .


    NSString *htmlString = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"dummytext" ofType:@"txt"] encoding:NSUTF8StringEncoding error:nil];


[YOURTEXTVIEW setValue:htmlString forKey:@"contentToHTMLString"];

This Load text from your textfile

check if an NSString contains 4 consecutive numbers --- IOS


- (BOOL)isSequence:(NSString *)string
{
    
    NSArray *arr = [NSArray arrayWithObjects:@"1234",@"2345",@"3456",@"4567",@"5678",@"6789"nil];
    
    BOOL found=NO;
    for (NSString *s in arr)
    {
        if ([string rangeOfString:s].location != NSNotFound) {
            NSLog(@"found");
            found = YES;
            break;
        }
    }

Thursday, September 26, 2013

Play Video from remote URL in UIWebView and MPMoviePlayerViewController ----- IOS

/***************************playVideoInWebView Start********************/
- (void)playVideoInWebView
{
 NSString *embedHTML = @"\
    <html><head>\
    <style type=\"text/css\">\
    body {\
    background-color: transparent;\
    color: white;\
    }\
    </style>\
    </head><body style=\"margin:0\">\
    <embed id=\"yt\" src=\"YOUR----URL--HERE \" type=\"application/x-shockwave-mp4\" \
    width=\"%0.0f\" height=\"%0.0f\"></embed>\
    </body></html>";
  
    webView = [[UIWebView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.bounds.size.width, self.view.bounds.size.height)];
  
    [self.webView setOpaque:NO];

    NSString *html = [NSString stringWithFormat:embedHTML, self.webView.frame.size.width, self.webView.frame.size.height];

    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"YOUR_URL_HERE"]]];

    [self.webView scalesPageToFit];

    webView.delegate = self;
  
    [self.view addSubview:webView];
 

}

/***************************playVideoInWebView End********************/



/***************************playVideoInMoviePlayer Start********************/

- (void)playVideoInPlayer
{
   moviePlayerController_ = [[MPMoviePlayerViewController alloc] init];
     url = [NSURL URLWithString:@"https://testvideo.fidelity.tv/asset/l6yo1b8uYfv.mp4?format=mobile_mp4"]; 
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlaybackDidFinish:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:nil];
   
    self.moviePlayerController_.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
    [self.moviePlayerController_.moviePlayer setContentURL:url];
    [self presentMoviePlayerViewControllerAnimated:self.moviePlayerController_];
   
}


- (void)moviePlaybackDidFinish:(NSNotification*)noti{

    NSLog(@"finish..%@",[noti userInfo]);
 
}

/***************************playVideoInMoviePlayer End********************/

stop deletion of complete text in case of secure Textfield on backspace.--- IOS

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
   
    // backspace functionality
    if (range.location > 0 && range.length == 1 && string.length == 0)
    {
        UITextPosition *beginning = textField.beginningOfDocument;
        UITextPosition *start = [textField positionFromPosition:beginning offset:range.location];
        NSInteger cursorOffset = [textField offsetFromPosition:beginning toPosition:start] + string.length;
        NSString *text = textField.text;

        // Trigger deletion
        [textField deleteBackward];

        if (textField.text.length != text.length - 1)
        {
            textField.text = [text stringByReplacingCharactersInRange:range withString:string];
            UITextPosition *newCursorPosition = [textField positionFromPosition:textField.beginningOfDocument offset:cursorOffset];
            UITextRange *newSelectedRange = [textField textRangeFromPosition:newCursorPosition toPosition:newCursorPosition];
            [textField setSelectedTextRange:newSelectedRange];
        }
        return NO;
    }   
       
    return YES;
}