Friday, April 26, 2013

change a sprite image in cocos2d iOS

CCTexture2D *firstImage = [[CCTextureCache sharedTextureCache] addImage:@"Image1.png"];

CCTexture2D *secondImage = [[CCTextureCache sharedTextureCache] addImage:@"Image2.png"];

CCSprite *sprite = [CCSprite spriteWithTexture: firstImage];


[self addChild:sprite];

 change the image of the sprite to secondImage:- 
sprite.texture = secondImage;

Tuesday, April 16, 2013

Determine device (iPhone,iPad , iPod Touch) with iPhone SDK


if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        {
            NSLog(@"I'm iPad");
    } else {
    NSString *deviceType = [UIDevice currentDevice].model;
                if([deviceType rangeOfString:@"iPhone"].location!=NSNotFound)
                {
                    NSLog(@"I m iPhone");

                } else {
                    NSLog(@" I'm  iPod");

                }
}

Thursday, April 11, 2013

Point the user back to the Location Services screen in the Settings app


[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"prefs:root=LOCATION_SERVICES"]];

Sunday, April 7, 2013

Get Custom Album name Using ALAsset Library IOS ....


 __block ALAssetsGroup* groupToAddTo;
    [self.library enumerateGroupsWithTypes:ALAssetsGroupAlbum
                                usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
                                     NSLog(@"[group valueForProperty:ALAssetsGroupPropertyName]  %@", [group valueForProperty:ALAssetsGroupPropertyName] );
                                    if ([[group valueForProperty:ALAssetsGroupPropertyName] isEqualToString:albumName]) {
                                        NSLog(@"found album %@", albumName);
                                        groupToAddTo = group;
                                    }
                                }
                              failureBlock:^(NSError* error) {
                                  NSLog(@"failed to enumerate albums:\nError: %@", [error localizedDescription]);
                              }];

Friday, April 5, 2013

Save Image to document directory IOS:-


Save Image to document directory:-

- (void)saveImage {

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:@"savedImage.png"];
    NSLog(@"savedImagePath..%@",savedImagePath);
    NSData *imageData = UIImagePNGRepresentation(Image);
    [imageData writeToFile:savedImagePath atomically:YES];  
    
  
}

Get Original Image from Photolibrary using ALAsset IOS


Get Original Image from Photolibrary:-

 ALAssetRepresentation *rep = [[dataContainer objectAtIndex:indexPath+1] defaultRepresentation];
    CGImageRef iref = [rep fullResolutionImage];
    if (iref) {
        UIImage *image = [UIImage imageWithCGImage:iref];
    }

Get images from photolibrary using ALAsset.... IOS


- (void)getImagesFromPhotoLibrary{ 
void (^assetsEnumeration)(ALAsset *,NSUInteger,BOOL *) = ^(ALAsset *asset,NSUInteger index,BOOL *stop){
        
        if(asset!=nil)
        {
            NSLog(@"obtained Asset %@",[asset valueForProperty:ALAssetPropertyURLs]);
            
            [self.dataContainer addObject:asset];
            NSLog(@"assest...%@",asset);
             [self setImage];
             
        }
       NSLog(@"data container...%@",self.dataContainer); 
    };
    
    void (^assetsGroupEnumeration)(ALAssetsGroup *,BOOL *) = ^(ALAssetsGroup *group,BOOL *status){
        
        if(group!=nil)
        {
            [group enumerateAssetsUsingBlock:assetsEnumeration];
        }
        
    };
    // allocate the library
    library = [[ALAssetsLibrary alloc]init];
    
    [library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:assetsGroupEnumeration failureBlock:^(NSError *error) {
        NSLog(@"Error :%@", [error localizedDescription]);
    }];
}



Set Image:-
    [imageview.image setImage:[UIImage imageWithCGImage:[(ALAsset*)[dataContainer objectAtIndex:indexPath ]thumbnail]]];

Wednesday, April 3, 2013

Get custom cell label text on didSelectRowAtIndexPath IOS....


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
myCustomCell *cell = (myCustomCell*)[tableView cellForRowAtIndexPath:indexPath];

NSLog(@"cell label text...%@",cell.textLabel.text);

}

Tuesday, April 2, 2013

set alarm for selected days in iphone using LocalNotification


If you have the time which you have to fire notification every day, you should do this:----
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSDateComponents *components = [[NSDateComponents alloc] init];
    for (NSMutableArray * alarmDayArr in self.reminderArr) {
        int count=[alarmDayArr count];
        if(!count){
            continue;
        }

        int day =0;
        int month=0;
        int year=0;
        int hour =0;
        int minutes=0;

        for ( int i=0;i<3;i++) {
            NSString * dayTime=[alarmDayArr objectAtIndex:i ];
            if (i==0) {
                day = [dayTime intValue];    
            }else if(i==1){
                month = [dayTime intValue];                    
            }else if(i==2){
                year = [dayTime intValue];    

            }
        }
        for ( int i=3;i<count;i++) {
            NSString * dayTime=[alarmDayArr objectAtIndex:i ];
            hour = [[dayTime substringToIndex:2] intValue];
            minutes = [[dayTime substringFromIndex:3] intValue];

            [components setDay:day];
            [components setMonth:month];
            [components setYear:year];
            [components setMinute:minutes];
            [components setHour:hour];


            NSDate *myNewDate = [calendar dateFromComponents:components];

            [self scheduleNotificationForDate:myNewDate];

        }
    }

    [components release];
    [calendar release];
then from here it will connect to the main notification firing method
[self scheduleNotificationForDate:myNewDate];
-(void) scheduleNotificationForDate: (NSDate*)date {
    /* Here we cancel all previously scheduled notifications */
    [[UIApplication sharedApplication] cancelAllLocalNotifications];
    UILocalNotification *localNotification = [[UILocalNotification alloc] init];
    localNotification.fireDate = date;
    NSLog(@"Notification will be shown on: %@ ",localNotification.fireDate);

    localNotification.timeZone = [NSTimeZone defaultTimeZone];
    localNotification.alertBody = @"Your Notification Text"
    localNotification.alertAction = NSLocalizedString(@"View details", nil);

    /* Here we set notification sound and badge on the app's icon "-1" 
     means that number indicator on the badge will be decreased by one 
     - so there will be no badge on the icon */

    localNotification.repeatInterval = NSDayCalendarUnit;
    localNotification.soundName = UILocalNotificationDefaultSoundName;
    localNotification.applicationIconBadgeNumber = -1;

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}