Thursday, April 25, 2013

Opcionalis delegate method

Egyreszt a @protocol-ban a method kapja meg az @optional direktivat:

@protocol MyProtocol
    @optional
    -(void)optionalProtocolMethod:(id)anObject;
@end

masreszt mivel ez onmagaban csak arra jo, hogy compiler ne adjon warningot meg a method meghivasa elott azt is meg kell nezni, hogy a delegate implementalja-e ezt a method-ot:

if ([delegate respondsToSelector:@selector(myOptionalMethod)]) {
    [delegate myOptionalMethod];
}
A protocol az NSObject-bol kell szarmazzon, mert annak a resze a respondsToSelector

Thursday, April 18, 2013

UIColor

Eleg furan mukodik, ha egy control RGB szinet be akarjuk allitani. a colorWithHue:saturation:brightness:alpha:-nal nem a sima RGB ertekeket kell megadni, hanem egy 0.0 es 1.0 koze eso float-ot, amit ugy kapunk meg, ha az alltalunk ismert RGB ertekeket elosztjuk 255-tel. Tehat peldaul a Red amit kaputunk 50, akkor itt 0.196-ot (50/255) kell megadnunk.

Ha egy UIColor-bol pedig ki szeretnenk nyerni az ertkeket arra a getRed:green:blue:alpha: methodot hasznalhatjuk valahogy igy:

UIColor *color = //get the color to log
CGFloat red = 0.0, green = 0.0, blue = 0.0, alpha = 0.0;
[color getRed:&red green:&green blue:&blue alpha:&alpha];
NSLog(@"mycolor red:%f green:%f blue:%f alpha:%f", red, green, blue, alpha);

Persze ha nem RGB hanem HSB akkor arra ott van a colorWithHue:saturation:brightness:alpha: es a 
getHue:saturation:brightness:alpha:

Monday, April 8, 2013

Email kuldese app-bol

MFMailComposeViewController-el egyszeruen:


- (void) sendEmail {
    if (![MFMailComposeViewController canSendMail]) {
        HBAlert(@"Can't send email", @"Sorry, your device is not able to send email");
        return;
    }
    MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
    [mailer setMailComposeDelegate:self];
    NSString *subject = @"Whatever subject;
    [mailer setSubject:subject];
    NSString *body = @"This is a test email from my app.";
    [mailer setMessageBody:body isHTML:NO];
    [mailer setModalPresentationStyle:UIModalPresentationFormSheet];
    [self presentViewController:mailer animated:YES completion:nil];
}


- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
    switch (result) {
        case MFMailComposeResultCancelled:
            NSLog(@"Mail cancelled");
            break;
        case MFMailComposeResultSaved:
            NSLog(@"Mail saved as draft");
            break;
        case MFMailComposeResultSent:
            NSLog(@"Mail is sent");
            break;
        case MFMailComposeResultFailed:
            NSLog(@"Sending mail failed");
            break;
        default:
            break;
    }
    [self dismissViewControllerAnimated:YES completion:nil];
}

Friday, April 5, 2013

DigitalColor Meter

Ha mac os-en kell egy keppont szinet megallapitani, akkor DigitalColor Meter.

Thursday, April 4, 2013

Handling Popover Controllers During Orientation Changes

Van egy azonos cimu bejegyzes az Apple-nel ami szerint:

When showing a popover controller, there are times when you will need to handle how the popover controller appears after a change in device orientation.

Situations when handling is required:

If the popover controller is presented from a target rectangle using the –presentPopoverFromRect:inView:permittedArrowDirections:animated: method of UIPopoverController.
If the popover controller is presented from a bar button item that is removed after the rotation has finished.

es ilyenkor a megoldas, ha ujra meghivjuk a presentPopoverFromRect:inView:permittedArrowDirections:animated: method-ot a didRotateFromInterfaceOrientation: eventben, csak azt nem teszik hozza, hogy elotte azert erdemes megnezni, hogy egyaltalan latszott-e a Popover Controller. Szoval helyesen igy nez ki:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
if ([myickerPopover isPopoverVisible]) {
[[self myPickerPopover] presentPopoverFromRect:
[[self myButton] frame] 
inView:[self view] 
permittedArrowDirections: UIPopoverArrowDirectionAny animated:YES];
}
}

Felteve, hogy a myPickerPopover es a myButton elerheto property.

dequeueReusableCellWithIdentifier:forIndexPath:

iOS 6-ban jelent meg a regi dequeueReusableCellWithIdentifier: mellett es ahogy a doksiban is kiemelik
Important: You must register a class or nib file using the registerNib:forCellReuseIdentifier: or registerClass:forCellReuseIdentifier: method before calling this method.

Azaz vagy marad a regi modszer ami akar 2-es iOS-en is mukodik:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell==nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }
return cell;
}


Vagy ha minimum 6-oson hasznaljuk akkor:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    
    return cell;
}

de ilyenkor fontos, hogy a viewDidLoad-ba betegyuk ezt:
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];




Friday, March 22, 2013

iOS app inditasa URL-lel

Be lehet regisztralni a sajat app-unkhoz URL-eket amikkel meg tudjuk nyitni az appot:
Target/Info/URL Types vagy Supporting Files/app-info.plist
Az identifiert (reverse domain name javasolt com.company.app - bar ez nem tul erdekes) es az URL Schema-t kell kitolteni.

Az app delegate-ben a application:openURL:sourceApplication:annotation method-ban lehet feldolgozni.

Tuesday, March 19, 2013

UISpitViewController-nel portrait modban a szoveges UIBarButtonItem kicserelese egy kepre

- (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController {

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    UIImage *customImage = [UIImage imageNamed:@"MyImage.png"];
    [button setBackgroundImage:customImage forState:UIControlStateNormal];
    [button setFrame:CGRectMake(0.0, 0.0, customImage.size.width, customImage.size.height)];
    [button addTarget:[barButtonItem target] action:[barButtonItem action] forControlEvents:UIControlEventTouchUpInside];
    [barButtonItem setCustomView:button];

    [self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];
    self.masterPopoverController = popoverController;
}

Monday, October 8, 2012

Smart App Banners

Ha azt akarjuk, hogy a mobile Safari egy oldal megnyitasanal automatikusan felkinalja egy app letolteset vagy inidtasat, akkor Smart App Banner-t kell hasznalni valahogy igy:

<meta name="apple-itunes-app" content="app-id=311507490"/>

innen: http://david-smith.org/blog/2012/09/20/implementing-smart-app-banners/

Thursday, March 8, 2012

#include/#import/@import

Az #import jobb, mert itt csak egyszer kerul be az improtalt resz es igy elkeruljuk a rekurziv #include-okat akkor is, ha az importalt file-ban nicsen rendesen megadva az include guard.

Jeremy W Sherman szerint az @import jobb lesz barmelyiknel.

Tuesday, March 6, 2012

keychain

Buzz Andersen: Simple iPhone Keychain Code
3 egyszeru method van benne es mukodik simulator-ban is meg device-on is:


+ (NSString *) getPasswordForUsername: (NSString *) username andServiceName: (NSString *) serviceName error: (NSError **) error;

+ (BOOL) storeUsername: (NSString *) username andPassword: (NSString *) password forServiceName: (NSString *) serviceName updateExisting: (BOOL) updateExisting error: (NSError **) error;

+ (BOOL) deleteItemForUsername: (NSString *) username andServiceName: (NSString *) serviceName error: (NSError **) error;


A code pedig itt van.
Egyebkent pedig: Keychain Services Programming Guide

+++++++++++
Itt pedig Chris Lowe peldaja ARC eseten.

Monday, March 5, 2012

screencapture


ScreenFlow - $99
SnapzProX - $66
iShowU - $20
SimFinger - free
PhoneFinger - free

Wednesday, February 29, 2012

Felix Schulze: Tutorial: iPhone App with compiled OpenSSL 1.0.0a Library

Itt van.

Ron Gutierrez: Accepting Un-Trusted Certificates Using The IOS Simulator

Itt van.

SubView-k kilogolasa


-(void) printAllChildrenOfView:(UIView*) view depth:(int) d {
    //Tabs are just for formatting
    NSString *tabs = @"";
    for (int i = 0; i < d; i++)
    {
        tabs = [tabs stringByAppendingFormat:@"\t"];
    }
    
    NSLog(@"%@%@", tabs, view);
    
    d++; //Increment the depth
    for (UIView *child in view.subviews)
    {
        [self printAllChildrenOfView:child depth:d];
    }
}

Thursday, February 9, 2012

Wednesday, February 1, 2012

Keyboard eltuntetes UITextField-nel

2 dolgot kell megenni:
- UITextField delagate-jet ra kell allitani a File's Owner-re
-textFieldShoudReturn(UITextFiled *)textField-ben meg kell hivni a textField-en a resignFirstResponder-t valahogy igy:

-(BOOL)textFieldShouldReturn:(UITextField *)theTextField {
    [uploadsURLTextField resignFirstResponder];
    return YES;
}

Wednesday, November 30, 2011

Categories (By Scott Stevenson)

innen


Categories are one of the most useful features of Objective-C. Essentially, a category allows you to add methods to an existing class without subclassing it or needing to know any of the details of how it's implemented.

This is particularly useful because you can add methods to built-in objects. If you want to add a method to all instances of NSString in your application, you just add a category. There's no need to get everything to use a custom subclass.

For example, if I wanted to add a method to NSString to determine if the contents is a URL, it would look like this:
 
#import @interface NSString (Utilities) - (BOOL) isURL; @end
This is very similar to a class declaration. The differences are that there is no super class listed, and there's a name for the category in parenthesis. The name can be whatever you want, though it should communicate what the methods inside do.

Here's the implementation. Keep in mind this is not a good implementation of URL detection. We're just trying to get the concept of categories across:
 
#import "NSString-Utilities.h" @implementation NSString (Utilities) - (BOOL) isURL { if ( [self hasPrefix:@"http://"] ) return YES; else return NO; } @end
Now you can use this method on any NSString. The following code will print "string1 is a URL" in the console:
 
NSString* string1 = @"http://pixar.com/"; NSString* string2 = @"Pixar"; if ( [string1 isURL] ) NSLog (@"string1 is a URL"); if ( [string2 isURL] ) NSLog (@"string2 is a URL");
Unlike subclasses, categories can't add instance variables. You can, however, use categories to override existing methods in classes, but you should do so very carefully.

Remember, when you make changes to a class using a category, it affects all instances of that class throughout the application.

Thursday, November 3, 2011

NSTemporaryDirecotory

A lenyeg, hogy Simulator-ban nem az app sandbox-aba mutat mint pl az NSHomeDirectory()

Igy amig a device-on:
NSHomeDirectory() == /var/mobile/Applications/[APP_ID]
NSTemporaryDirectory() == /private/var/mobile/Applications/[APP_ID]/tmp/
addig iOS Simulatorban:
NSHomeDirectory() == /Users/[USER]/Library/Application Support/iPhone Simulator/5.0/Applications/[APP_ID]
NSTemporaryDirectory == /var/folders/oA/[ID]/-Tmp-/

Do you use the temporary directory? On Simulator NSTemporaryDirectory() returns Mac OS X tmp, a path in /var, which is outside the application sandbox.

#if TARGET_IPHONE_SIMULATOR
NSString *tmpPath = [NSHomeDirectory() stringByAppendingPathComponent: @"tmp"];
#else
NSString *tmpPath = NSTemporaryDirectory();
#endif

Tuesday, October 25, 2011

Halozat sebessegenek korlatozasa

Ha mondjuk 3G sebesseggek akarunk valamit simulatorban kiprobalni akkor jol johetnek ezek:

Ha Lion van a gepen, akkor Network Link Conditioner

Ha nincs Lion akkor is van par megoldas:

1. termialbol IP firewall rule-lal:

sudo ipfw add 500 pipe 1 ip from any to any 
sudo ipfw pipe 1 config bw 112kbit/s plr 0 delay 20ms
vissza pedig:
sudo ipfw delete 500

-50 USD, de van free trial
-Windows, Mac OS, Linux
-sok mas dologra is jo

-lehet domain-ekre korlatozni

Thursday, October 20, 2011

AgentM: A Better NSLog()

Itt van, meg 2005-bol.

Tuesday, October 18, 2011

Matt Gallagher: Variable argument lists in Cocoa

Itt van, de ami nekem kellett azt bemasolom:

The va_list, va_start, va_arg and va_end are all standard C syntax for handling variable arguments. To describe them simply:

  • va_list - A pointer to a list of variable arguments.
  • va_start - Initializes a va_list to point to the first argument after the argument specified.
  • va_arg - Fetches the next argument out of the list. You must specify the type of the argument (so that va_arg knows how many bytes to extract).
  • va_end - Releases any memory held by the va_list data structure.

Generally speaking, you can use this for loop for any variable argument situation where your arguments are all the same type. Other cases are a bit trickier but far less common — I'm sure you can work out how they would work if needed.

va_list in Cocoa

A number of classes in Cocoa have methods that take variable numbers of arguments. In most cases, these classes will also have an equivalent method that takes a va_list.

We can see an example of these va_list equivalents by looking at NSString. NSString declares the class method stringWithFormat:... (which takes a variable number of arguments) andNSString also declares the instance method initWithFormat:arguments: (where the argumentsparameter is a va_list) which handles the equivalent behavior of stringWithFormat:....

These va_list methods are used in the situation where your class defines a method with a variable argument list and you need to pass those variable arguments into the Cocoa method. For example, if the StringContainer class listed above declared the method:

- (void)setContentsWithFormat:(NSString *)formatString, ...;

The implementation of this method would be as follows:

- (void)setContentsWithFormat:(NSString *)formatString, ...
{
[contents autorelease];
va_list args;
va_start(args, formatString);
contents = [[NSString alloc] initWithFormat:formatString arguments:args];
va_end(args);
}

The va_list parameter allows us to pass our own variable argument list to the Cocoa method so that the Cocoa method can handle the arguments.