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;
}

Wednesday, September 25, 2013

How to stop --- if space is pressed twice, a full-stop gets appeared automatically --- IOS

Replace " . " with space ----- if space is pressed twice, a full-stop gets appeared automatically ---- IOS



if ( (range.location > 0 && [string length] > 0 &&
          [[NSCharacterSet whitespaceCharacterSet] characterIsMember:[string characterAtIndex:0]] &&
          [[NSCharacterSet whitespaceCharacterSet] characterIsMember:[[textField text] characterAtIndex:range.location - 1]]) )
    {
        //Manually replace the space with your own space, programmatically
        textField.text = [textField.text stringByReplacingCharactersInRange:range withString:@" "];

        //Tell Cocoa not to insert its space, because you've just inserted your own
        return NO;
    }



//User not enter after 1st space in UITextField --- ios

return !(range.location > 0 &&
             [string length] > 0 &&
             [[NSCharacterSet whitespaceCharacterSet] characterIsMember:[string characterAtIndex:0]] &&
             [[NSCharacterSet whitespaceCharacterSet] characterIsMember:[[textField text] characterAtIndex:range.location - 1]]);

Tuesday, September 24, 2013

Check if a UITextField has blank spaces entered --- ios

NSString *rawString = [textField text];
NSCharacterSet *whitespace = [NSCharacterSet whitespaceAndNewlineCharacterSet];
NSString *trimmed = [rawString stringByTrimmingCharactersInSet:whitespace];
if ([trimmed length] == 0) {
    // Text was empty or only whitespace.
}

Monday, September 23, 2013

easy way to dismiss keyboard if it is on screen --- ios

- (void)resignKeyBoard{

    [self.view endEditing:YES];
   

}

DEtect if Keyboard is present on screen or not ....-- IOS

- (void) isKeyboardOnScreen
{
    BOOL isKeyboardShown = NO;
   
    NSArray *windows = [UIApplication sharedApplication].windows;
    if (windows.count > 1) {
        NSArray *wSubviews =  [windows[1]  subviews];
        NSLog(@"wSubviews..%@",wSubviews);
        isKeyboardShown = YES;
      
       

    }
   
     NSLog(@"isKeyboardShown...%d",isKeyboardShown);
}

Tuesday, September 17, 2013

Capitalise first letter in String --- ios

- (NSString*)capitaliseFirstLetterInString:(NSString*)textString{
    NSString *text = textString;
    NSString *capitalizedString = [[[text substringToIndex:1] uppercaseString] stringByAppendingString:[text substringFromIndex:1]];
   
    NSLog(@"%@ uppercased is %@", text, capitalizedString);
    return capitalizedString;
}