MT Demo

ViewController.h

#import <UIKit/UIKit.h>

#import <AVFoundation/AVFoundation.h>

#import <MediaPlayer/MediaPlayer.h>

@interface ViewController : UIViewController <UITableViewDataSource,UITableViewDelegate>

@property MPMoviePlayerViewController *moviePlayer;

@end

ViewController.m

#import “ViewController.h”

@interface ViewController ()

@property NSArray * jsonData ;

@property NSMutableArray *name;

@property NSMutableArray *photo;

@property NSMutableArray *url;

@end

@implementation ViewController

– (void)viewDidLoad {

    [super viewDidLoad];

    

    self.name = [[NSMutableArray alloc] init];

    self.photo = [[NSMutableArray alloc] init];

    self.url = [[NSMutableArray alloc] init];

    

    NSURL *url = [NSURL URLWithString:@”http://project-demo-server.info/iphonevideo/displayvieo.php?cat=office&#8221;];

    

    NSData *data = [NSData dataWithContentsOfURL:url];

    

    NSData *photo ;

    

    self.jsonData = [NSJSONSerialization JSONObjectWithData:data options:nil error:nil];

    

    for(int i = 0; i<self.jsonData.count; i++)

    {

        

        [self.name addObject:[[self.jsonData objectAtIndex:i] valueForKey:@”videoname”]];

        

        

        photo = [[NSData alloc] initWithContentsOfURL:[[NSURL alloc] initWithString:@”http://www.project-demo-server.info/iphonevideo/images/Neck-and-Wrist-Stretches.jpg&#8221;]];

        

        [self.photo addObject:[UIImage imageWithData:photo]];

        

        [self.url addObject:[[NSURL alloc ] initWithString:[[self.jsonData objectAtIndex:i] valueForKey:@”video”]]] ;

    

    }

    // Do any additional setup after loading the view, typically from a nib.

}

– (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

– (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

#warning Potentially incomplete method implementation.

    // Return the number of sections.

    return 1;

}

– (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

#warning Incomplete method implementation.

    // Return the number of rows in the section.

    return [self.name count];

}

– (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@”cell” forIndexPath:indexPath];

     if(cell == nil)

     {

     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@”cell”];

     }

     

     cell.textLabel.text = [self.name objectAtIndex:indexPath.row];

     

     cell.imageView.image = [self.photo objectAtIndex:indexPath.row];

     

return cell;

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    

   // NSString *path = [[NSBundle mainBundle]pathForResource:

                     // @”videoTest” ofType:@”mov”];

    

    self.moviePlayer = [[MPMoviePlayerViewController

                    alloc]initWithContentURL:[self.url objectAtIndex:indexPath.row]];

    [self presentModalViewController:self.moviePlayer animated:NO];

}

@end

Simple API Load in TableView

//Add AFNetworking FrameWork………………With UtilityLibrary and AFNetworking…. With .xib CELL or Implement Tablecell In Class

NewsEventsCellTableViewCell.h

#import <UIKit/UIKit.h>

@interface NewsEventsCellTableViewCell : UITableViewCell{

        IBOutlet UIImageView *imgLblBg;

      IBOutlet UILabel *lblDate;

}

@property (nonatomic , retain) IBOutlet UIImageView *imgLblBg;

@property (nonatomic , retain) IBOutlet UILabel *lblDate;

@end

=============================

NewsEventsCellTableViewCell.m

#import “NewsEventsCellTableViewCell.h”

@implementation NewsEventsCellTableViewCell

@synthesize imgLblBg,lblDate;

– (void)awakeFromNib {

    // Initialization code

}

– (void)setSelected:(BOOL)selected animated:(BOOL)animated {

    [super setSelected:selected animated:animated];

    // Configure the view for the selected state

}

@end

#import <UIKit/UIKit.h>

@interface NewsEventsCellTableViewCell : UITableViewCell{

    

    IBOutlet UIImageView *imgLblBg;

    

    IBOutlet UILabel *lblDate;

}

@property (nonatomic , retain) IBOutlet UIImageView *imgLblBg;

@property (nonatomic , retain) IBOutlet UILabel *lblDate;

@end

NewsEventsVC.h

#import <UIKit/UIKit.h>

@interface BranchListCell : UITableViewCell

@property (strong, nonatomic) IBOutlet UILabel *lblBranchName;

@property (strong , nonatomic) IBOutlet UIImageView *imgArrow;

@end

@interface NewsEventsVC : UIViewController{

    

    IBOutlet UILabel *lblHeader;

    

    IBOutlet UIImageView *imgTopView;

    }

@property (weak, nonatomic) IBOutlet UITableView *tableVIew;

@property (nonatomic, strong) NSMutableArray *tableViewDataSources;

@end

===============================================

NewsEventsVC.m

#import “NewsEventsVC.h”

#import “UtilityLibrary.h”

#import “NewsEventsCellTableViewCell.h”

@implementation BranchListCell

@end

@interface NewsEventsVC ()

@end

@implementation NewsEventsVC

– (void)viewDidLoad {

    [super viewDidLoad];

    self.tableViewDataSources = [[NSMutableArray alloc] init];

    [self getNewsEventsList];

}

#pragma mark – UITableView DataSource and Delegate Methods –

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    return 1;

}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return self.tableViewDataSources.count;

}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    /*NewsEventsCellTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@”NewsEventsCellTableViewCell”];

    if (cell == nil) {

        

        NSArray *array = [[NSBundle mainBundle] loadNibNamed:@”NewsEventsCellTableViewCell” owner:self options:nil];

        cell = [array objectAtIndex:0];

    }

    NSLog(@”tableViewDataSources==>%@”,self.tableViewDataSources);

    cell.lblDate.text = [NSString stringWithFormat:@”%@”,[[self.tableViewDataSources objectAtIndex:indexPath.row] objectForKey:@”HospitalBranchName”]];

    */

    

    NSString * identifier=[NSString stringWithFormat:@”BranchListCell”];

    BranchListCell *cell=(BranchListCell *)[tableView dequeueReusableCellWithIdentifier:identifier];

    if(cell == nil){

        cell=[[BranchListCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier ];

    }

    cell.lblBranchName.text = [NSString stringWithFormat:@”%@”,[[self.tableViewDataSources objectAtIndex:indexPath.row] objectForKey:@”HospitalBranchName”]];

     return cell;

}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

    return 92;

}

#pragma mark – Remove Space In URl

-(NSString *)encodesmiliesandstring:(NSString *)convertstring

{

    NSString *convertedstring=[NSString stringWithString:convertstring];

    convertedstring=[convertedstring stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    return convertedstring;

}

-(void)getNewsEventsList

{

    

//http://www.dev3.mybynde.com/desktopmodules/HaloWebAPI/API/Hospital/GetHospitalBranchByHospitalID?HospitalID=HOS4341&UserID=2110&UserRole=Hospital_Admin

    NSString *strURL = @”http://www.dev3.mybynde.com/desktopmodules/HaloWebAPI/API/&#8221;; //LIVE

    

        NSString * url=[NSString stringWithFormat:@”%@Hospital/GetHospitalBranchByHospitalID?HospitalID=%@&UserID=%@&UserRole=%@”,strURL,@”HOS4341″,@”2110″,@”Hospital_Admin”]; //old

        

        NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[self encodesmiliesandstring:url]] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:9000];

        [theRequest setHTTPMethod:@”GET”];

        [theRequest addValue:@”application/json” forHTTPHeaderField:@”Content-Type”];

        NSLog(@”webservice called for post is %@”,theRequest);

        

    

        [NSURLConnection sendAsynchronousRequest:theRequest queue:[NSOperationQueue mainQueue]completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)

         

         {

             

             if ([(NSHTTPURLResponse *)response statusCode]==200)

             {

                 

                 NSMutableDictionary *jsonObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];

                 NSString * resultStr = [jsonObject objectForKey:@”Result”];

                 if([resultStr isEqualToString:@”True”]){

                     

                     //Add All Json Responce In branchListArr….. for display in TableView List…..

                     _tableViewDataSources=[jsonObject valueForKey:@”HospitalBranchList”];

                     

//                     NSMutableArray *arryHospital = [[NSMutableArray alloc] init];

//                     [arryHospital addObject:jsonObject];

//                     strImg = [[[arryHospital objectAtIndex:0] valueForKey:@”Hospital”] valueForKey:@”HospitalLogo”];

//                     

//                    

//                     [_imgLogo sd_setImageWithURL:[NSURL URLWithString:strImg]

//                                 placeholderImage:nil

//                                        completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {

//                                            

//                                            // [MBProgressHUD hideAllHUDsForView:self.view animated:YES];

//                                            if (image){

//                                                [_imgLogo setImage:image];

//                                                [_objActivity stopAnimating];

//                                                _objActivity.hidden = YES;

//                                            }else{

//                                                [_objActivity stopAnimating];

//                                            }

//                                        }];

                     [_tableVIew reloadData];

                 }

                 else{

                     NSLog(@”False”);

                 }

             }

             else

             {

                 UIAlertView * alert =[[UIAlertView alloc]initWithTitle:@”Alert!”

                                                                message:@”Could not connect to the network. Please try again in a few seconds.”

                                                               delegate:nil

                                                      cancelButtonTitle:@”Ok”

                                                      otherButtonTitles:nil, nil];

                 [alert show];

                 

             }

         }];

        

   

    

    

}

@end

WS and ADD in DB

1)//IN APPDELEGATE……………………….

 

– (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.

       [self checkDatabase];

    return YES;

   }

– (void)checkDatabase

{

    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *documentsDir = [documentPaths objectAtIndex:0];

    NSString *databasePath = [documentsDir stringByAppendingPathComponent:@”TestData.sqlite”];

    NSString *databaseName = @”TestData.sqlite”;

    NSFileManager *fileManager = [NSFileManager defaultManager];

        NSLog(@”%@ === %@”,databaseName,databasePath);

        if(![fileManager fileExistsAtPath:databasePath])

    {

        NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath]

                                         stringByAppendingPathComponent:databaseName];

        [fileManager removeItemAtPath:databasePath error:nil];

        [fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil];

    }

    else

    {

        NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName];

        [fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil];

    }

}

2) Add Class TestData add as NSObject……..

TestData.h

#import <Foundation/Foundation.h>

#import “sqlite3.h”

@interface TestData : NSObject

@property (nonatomic, readwrite) NSInteger  VideoID;

@property (nonatomic, strong) NSString   *videoName;

@property (nonatomic, strong) NSString   *imgPhoto;

@property (nonatomic, strong) NSString   *imgVideoURl;

+ (NSInteger)addRecord:(TestData *)sObj;

+ (NSMutableArray *)readRecords;

@end

TestData.m

#import “TestData.h”

@implementation TestData

+ (NSInteger)addRecord:(TestData *)sObj

{

    NSInteger retVal = false;

    

    NSString *query = [NSString stringWithFormat:

                       @”INSERT INTO TestData (videoName, imagePhoto, imageVideoUrl) VALUES (‘%@’, ‘%@’, ‘%@’)”,

                       sObj.videoName,

                       sObj.imgPhoto,

                       sObj.imgVideoURl

                       ];

    

    sqlite3 *db;

    

    

    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *documentsDir = [documentPaths objectAtIndex:0];

    NSString *dbPath = [documentsDir stringByAppendingPathComponent:@”TestData.sqlite”];

    

    

    

    if(sqlite3_open([dbPath UTF8String], &db) == SQLITE_OK)

    {

        sqlite3_stmt *compiledStatement;

        

        if(sqlite3_prepare_v2(db,[query UTF8String], -1, &compiledStatement, NULL) == SQLITE_OK)

        {

            sqlite3_step(compiledStatement);

        }

        

        sqlite3_finalize(compiledStatement);

        

        retVal = sqlite3_last_insert_rowid(db);

        

        

        

    }

    sqlite3_close(db);

    

    return retVal;

}

+ (NSMutableArray *)readRecords

{

    NSMutableArray *recordsArr = [[NSMutableArray alloc] init];

    

    NSString *query = [NSString stringWithFormat:@”SELECT * FROM TestData ORDER BY videoName”];

    

    sqlite3 *db;

    

    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *documentsDir = [documentPaths objectAtIndex:0];

    NSString *dbPath = [documentsDir stringByAppendingPathComponent:@”TestData.sqlite”];

    

    if(sqlite3_open([dbPath UTF8String], &db) == SQLITE_OK)

    {

        sqlite3_stmt *compiledStatement;

        

        

        if(sqlite3_prepare_v2(db,[query UTF8String], -1, &compiledStatement, NULL) == SQLITE_OK)

        {

            while(sqlite3_step(compiledStatement) == SQLITE_ROW)

            {

               

      TestData *sObj = [[TestData alloc] init];

                

                sObj.VideoID = sqlite3_column_int(compiledStatement, 0);

                

                sObj.videoName = [NSString stringWithUTF8String😦char *)sqlite3_column_text(compiledStatement, 1)];

                sObj.imgPhoto = [NSString stringWithUTF8String😦char *)sqlite3_column_text(compiledStatement, 2)];

                sObj.imgVideoURl = [NSString stringWithUTF8String😦char *)sqlite3_column_text(compiledStatement, 3)];

                [recordsArr addObject:sObj];

                

                NSLog(@”%@”,sObj);

            }

        }

        sqlite3_finalize(compiledStatement);

    }

    sqlite3_close(db);

    

    return recordsArr;

}

@end

3)MyVideoCell.h with .XIB

#import <UIKit/UIKit.h>

#import “TestData.h”

@interface MyVideoCell : UIViewController

@property (nonatomic, strong) IBOutlet UILabel  *lblVideoName;

@property (nonatomic, strong) IBOutlet UIImageView  *imgVideo;

@property (nonatomic, strong) TestData *testObj;

@end

MyVideoCell.m

#import “MyVideoCell.h”

@interface MyVideoCell ()

@end

@implementation MyVideoCell

– (void)viewDidLoad {

    [super viewDidLoad];

    

    [self.lblVideoName setText:self.testObj.videoName];

    

    NSString *ImageURL = self.testObj.imgPhoto;

    NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:ImageURL]];

    self.imgVideo.image = [UIImage imageWithData:imageData];

    // Do any additional setup after loading the view from its nib.

}

– (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

/*

#pragma mark – Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation

– (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    // Get the new view controller using [segue destinationViewController].

    // Pass the selected object to the new view controller.

}

*/

@end

ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>

{

    IBOutlet UITableView *tblData;

    NSMutableArray *recordArr;

}

@end

ViewController.m

#import “ViewController.h”

#import “MyVideoCell.h”

#import “TestData.h”

#import “VideoVC.h”

@interface ViewController ()

@end

@implementation ViewController

– (void)viewDidLoad {

    [super viewDidLoad];

}

– (void)viewWillAppear:(BOOL)animated

{

    [super viewWillAppear:animated];

    

    recordArr = [TestData readRecords];

    

    [tblData reloadData];

}

– (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

    return 60;

}

– (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return recordArr.count;

}

– (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@”Cell”];

    

    cell.selectionStyle = UITableViewCellSelectionStyleGray;

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    

    TestData *currentSobj = recordArr[indexPath.row];

    

    MyVideoCell *mcv = [[MyVideoCell alloc] init];

    

    mcv.testObj = currentSobj;

    

    

    [cell.contentView addSubview:mcv.view];

    

    return cell;

}

– (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    VideoVC *vc = [self.storyboard instantiateViewControllerWithIdentifier:@”VideoVC”];

    

    vc.testObj = recordArr[indexPath.row];

    

    [self.navigationController pushViewController:vc animated:YES];

}

– (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

@end

PUSH NOTIFICATION METHODS…..

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)

    {

        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound |UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];

        [[UIApplication sharedApplication] registerForRemoteNotifications];

    }

    else

    {

        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:

         (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];

    }

– (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error

{

NSLog(@”%@”,[error description]);

 

}

– (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken

{

strDeviceToken=[[[deviceToken description]

                     stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@”<>”]]

                    stringByReplacingOccurrencesOfString:@” ” withString:@””];

    

    

    NSLog(@”%@”,strDeviceToken);

    

    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];

    

    [prefs setObject:strDeviceToken forKey:token1];

    

    [prefs synchronize];

}

ATTRIBUTEDSTRING

NSString *offerName = [dictSetdata objectForKey:@”offerName”];

    NSString *offerDescription = [NSString stringWithFormat:@”\n\n%@”,[dictSetdata objectForKey:@”offerDescription”]];

    

    

    NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:offerName];

    NSRange newRange = NSMakeRange(0, string.length);

    [string addAttribute:NSFontAttributeName value:[UIFont fontWithName:lblDescriptionFont size:14.0f] range:newRange];

    

    NSMutableAttributedString * stringDEsc = [[NSMutableAttributedString alloc] initWithString:offerDescription];

    NSRange newRange1 = NSMakeRange(0, stringDEsc.length);

    [stringDEsc addAttribute:NSFontAttributeName value:[UIFont fontWithName:lblAddressFont size:14.0f] range:newRange1];

    [string appendAttributedString:stringDEsc ];

    

    [self.txtOfferName setAttributedText:string];

    [self.txtOfferName setTextAlignment:NSTextAlignmentCenter];

URL WITH TEXT/HTML…..

NSURL *URL = [NSURL URLWithString:@”http://www.raywenderlich.com/demos/weather_sample/weather.php?format=json“];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];

AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc] initWithRequest:request];
op.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@”text/html”];
op.responseSerializer = [AFJSONResponseSerializer serializer];
[op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@”JSON: %@”, responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@”Error: %@”, error);
}];
[[NSOperationQueue mainQueue] addOperation:op];