• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            逛奔的蝸牛

            我不聰明,但我會很努力

               ::  :: 新隨筆 ::  ::  :: 管理 ::

            1. Open URL in Safari

                NSURL *url = [ [ NSURLalloc ] initWithString@" ];

                [[UIApplication sharedApplication] openURL:url];


            2. Date Formatting on iPhone and Cocoa

                //Format Date

                NSDateFormatter *dateFormat = [[NSDateFormatterallocinit];

                [dateFormat setDateFormat@"yyyy-MM-dd HH:mm:ss zzz"]; // 2009-02-01 19:50:41 PST

                NSString *dateString = [dateFormat stringFromDate: [scoreDataobjectForKey@"date"]];

            3. Get iPhone Application Version Number

                NSString*version = [[[NSBundlemainBundleinfoDictionaryobjectForKey:@"CFBundleVersion"];

            4. Duplicate Xcode project

                1. Copy/rename the folder into new name

                2. Get inside the new folder and rename the .pch and .xcodeproj files

                3. Delete the build folder

                4. Open .xcodeproj file in text editor, like TextMate or TextWrangler. That’s actually a folder, which contains 4 files (you can also right-click and do Show package contents, which will reveal the files)

                5. Open project.pbxproj in text editor and replace all instances of the old name with the new name

                6. Load the project file in XCode, do Build/Clean all targets

            5. iPhone HTTP request

                 //prepar request

                 NSString *urlString = [NSStringstringWithFormat:@"];

                 NSMutableURLRequest *request = [[[NSMutableURLRequestallocinitautorelease];

                 [request setURL:[NSURLURLWithString:urlString]];

                 [request setHTTPMethod:@"POST"];

                 //set headers

                 NSString *contentType = [NSStringstringWithFormat:@"text/xml"];

                 [request addValue:contentType forHTTPHeaderField: @"Content-Type"];

                

                 //create the body

                 NSMutableData *postBody = [NSMutableDatadata];

                 [postBody appendData:[[NSStringstringWithFormat:@"<xml>"dataUsingEncoding:NSUTF8StringEncoding]];

                 [postBody appendData:[[NSStringstringWithFormat:@"<yourcode/>"dataUsingEncoding:NSUTF8StringEncoding]];

                 [postBody appendData:[[NSStringstringWithFormat:@"</xml>"dataUsingEncoding:NSUTF8StringEncoding]];

                 //post

                 [request setHTTPBody:postBody];

                 //get response

                 NSHTTPURLResponse* urlResponse = nil;  

                 NSError *error = [[NSErroralloc] init];  

                 NSData *responseData = [NSURLConnectionsendSynchronousRequest:request returningResponse:&urlResponse error:&error];  

                 NSString *result = [[NSStringallocinitWithData:responseData encoding:NSUTF8StringEncoding];

                 NSLog(@"Response Code: %d", [urlResponse statusCode]);

                 if ([urlResponse statusCode] >= 200 && [urlResponse statusCode] < 300) {

                      NSLog(@"Response: %@", result);

                    

                      //here you get the response  

                 }

            6. Load Image from URL and then Resize

                NSString* imageURL = [NSString stringWithFormat: @"http://theimageurl.com/?id=%@", [[resultsEntries objectAtIndex:0] objectForKey: @"image_large"]];

                NSData* imageData = [[NSDataalloc]initWithContentsOfURL:[NSURLURLWithString:imageURL]];

                UIImage* image = [[UIImageallocinitWithData:imageData];

                

                // resize image

                CGSize newSize = CGSizeMake(100100);

                UIGraphicsBeginImageContext( newSize );// a CGSize that has the size you want

                [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];

                

                //image is the original UIImage

                UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();

                UIGraphicsEndImageContext();

                

                imageHeight = image.size.height;

                [imageMain setImage:newImage];

                [imageData release];

                [image release];

            7. iPhone: transition between views

                // get the view that's currently showing

                UIView *currentView = self.view;

                // get the the underlying UIWindow, or the view containing the current view view

                UIView *theWindow = [currentView superview];

                

                // remove the current view and replace with myView1

                [currentView removeFromSuperview];

                [theWindow addSubview:view1];

                

                // set up an animation for the transition between the views

                CATransition *animation = [CATransition animation];

                [animation setDuration:0.5];

                [animation setType:kCATransitionPush];

                [animation setSubtype:kCATransitionFromRight];

                [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

                

                [[theWindow layer] addAnimation:animation forKey:@"SwitchToView1"];

            8. get iPhone ip address

            #include <ifaddrs.h>

            #include <arpa/inet.h>

            - (NSString*)getIPAddress {

                NSString *address = @"error";

                structifaddrs *interfaces = NULL;

                structifaddrs *temp_addr = NULL;

                int success = 0;

                // retrieve the current interfaces - returns 0 on success

                success = getifaddrs(&interfaces);

                if (success == 0) {

                    // Loop through linked list of interfaces

                    temp_addr = interfaces;

                    while(temp_addr != NULL) {

                        if(temp_addr->ifa_addr->sa_family == AF_INET) {

                            // Check if interface is en0 which is the wifi connection on the iPhone

                            // Mac 里用en0

                            if([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en1"]) {

                                // Get NSString from C String

                                address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];

                            }

                        }

                        temp_addr = temp_addr->ifa_next;

                    }

                }

                // Free memory

                freeifaddrs(interfaces);

                

                return address;

            }

            9. Useful Cocoa Macros

            #define APP_NAME [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"]

            #define APP_VERSION [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]

            #define OPEN_URL(urlString) [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:urlString]]


            // Retrieving preference values

            #define PREF_KEY_VALUE(x) [[[NSUserDefaultsController sharedUserDefaultsController] values] valueForKey:(x)]

            #define PREF_KEY_BOOL(x) [(PREF_KEY_VALUE(x)) boolValue]

            #define PREF_SET_KEY_VALUE(x, y) [[[NSUserDefaultsController sharedUserDefaultsController] values] setValue:(y) forKey:(x)]

            #define PREF_OBSERVE_VALUE(x, y) [[NSUserDefaultsController sharedUserDefaultsController] addObserver:y forKeyPath:x options:NSKeyValueObservingOptionOld context:nil];


            /* key, observer, object */

            #define OB_OBSERVE_VALUE(x, y, z) [(z) addObserver:y forKeyPath:x options:NSKeyValueObservingOptionOld context:nil];


            #ifdef __OBJC__

            staticinlineBOOL isEmpty(id thing) {

                return thing == nil

            || ([thing respondsToSelector:@selector(length)]

                    && [(NSData *)thing length] == 0)

            || ([thing respondsToSelector:@selector(count)]

                    && [(NSArray *)thing count] == 0);

            }

            #endif

            10. iPhone OS - Vibration - Simple Version

            Creating a vibration is simple as pie - simpler in fact. It just requires one line of code; two if you add the import line. But as simple as a one-liner is it is better to make it into a function. So here is the one liner, followed by the function.

            //  NOTE: You need to import the AudioToolbox for access to the vibrate

            #import <AudioToolbox/AudioToolbox.h>


            //  The one-liner:

            AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);


            //  The function:

            - (void)vibrate {

                AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

            }


            //  The call from within another method in the same class:

            - (void)myMethod {

                [self vibrate];

            }

            @import url(http://www.shnenglu.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
            99久久国产亚洲综合精品| 伊人久久大香线蕉亚洲| 久久久久久久精品成人热色戒| 欧美亚洲另类久久综合婷婷| 少妇久久久久久被弄到高潮| 久久久久av无码免费网| 欧美精品久久久久久久自慰| 日本精品久久久中文字幕| 精品久久久久久无码国产| 久久久久久久久久久久久久 | 国产美女亚洲精品久久久综合| 无码人妻久久一区二区三区免费丨 | 91久久精品91久久性色| 久久精品不卡| 色欲综合久久躁天天躁蜜桃| 国产精品VIDEOSSEX久久发布| 久久久久久久久波多野高潮| 国产精品免费久久久久电影网| 久久久久久精品免费看SSS | 国产国产成人精品久久| 亚洲一区精品伊人久久伊人 | 久久综合五月丁香久久激情| 色欲久久久天天天综合网| 久久亚洲国产成人影院网站| 精品午夜久久福利大片| 亚洲va中文字幕无码久久| 久久综合伊人77777麻豆| 国产精品久久久久久久久免费| 77777亚洲午夜久久多人| 国产叼嘿久久精品久久| 中文字幕久久欲求不满| 久久久亚洲欧洲日产国码aⅴ | 久久亚洲AV无码精品色午夜麻豆 | 国产亚洲婷婷香蕉久久精品| 囯产精品久久久久久久久蜜桃 | 久久ZYZ资源站无码中文动漫| 久久精品综合一区二区三区| 国产福利电影一区二区三区久久久久成人精品综合 | 久久影视综合亚洲| 97精品伊人久久久大香线蕉| 狠狠色婷婷综合天天久久丁香|