tag:blogger.com,1999:blog-3263454819325798702024-03-13T17:56:42.500+08:00iOS App SharingShare the programming experience in iOS application development.Unknownnoreply@blogger.comBlogger61125tag:blogger.com,1999:blog-326345481932579870.post-42575037800012175452014-08-21T22:07:00.001+08:002014-08-21T22:07:18.877+08:00The new app are available in App StoreLeft Brian's training: improve the game flow by click one button instead of two buttons to move to next question.<br />
<br />
https://itunes.apple.com/us/app/left-brains-training/id477059883?mt=8<br />
<br />
Sushi Book: fix bug that the new database is always available.<br />
<br />
https://itunes.apple.com/us/app/sushi-book/id500375284?mt=8<br />
<br />
SoundRec: new app to record the voice memo in the meeting, lecture, & etc.<br />
<br />
https://itunes.apple.com/us/app/soundrec/id899045542?mt=8<br />
<br />
<br />
<br />Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-326345481932579870.post-10498713076063207912013-04-03T13:09:00.002+08:002013-04-05T11:34:16.844+08:00Dismiss Numpad/keyboard when touching outside UITextFieldThere are two kinds of method to achieve it.<br />
<br />
Method 1:<br />
<br />
<span style="background-color: white; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px; text-align: left;">To add an UITapGestureRecogniser and assign it to the view, and then call the function to resign the keyboard.</span><br />
<span style="background-color: white; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px; text-align: left;"><br /></span>
<span style="background-color: white; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px; text-align: left;">in viewDidLoad:</span><br />
<br />
<pre class="lang-c prettyprint prettyprinted" style="border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; line-height: 18px; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; text-align: left; vertical-align: baseline; width: auto;"><code style="background-color: white; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; margin: 0px; padding: 0px; vertical-align: baseline;"><span class="typ" style="border: 0px; color: #2b91af; margin: 0px; padding: 0px; vertical-align: baseline;">UITapGestureRecognizer</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">*</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">tap </span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">[[</span><span class="typ" style="border: 0px; color: #2b91af; margin: 0px; padding: 0px; vertical-align: baseline;">UITapGestureRecognizer</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> alloc</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">]</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
initWithTarget</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">:</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">self
action</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">:</span><span class="lit" style="border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">@selector</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">dismissKeyboard</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">)];</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">[</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">self</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">.</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">view addGestureRecognizer</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">:</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">tap</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">];</span></code></pre>
<pre class="lang-c prettyprint prettyprinted" style="border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; line-height: 18px; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; text-align: left; vertical-align: baseline; width: auto;"><code style="border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; margin: 0px; padding: 0px; vertical-align: baseline;"><span class="pun" style="background-color: white; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">-(<span class="kwd" style="border: 0px; color: darkblue; margin: 0px; padding: 0px; vertical-align: baseline;">void</span>)dismissKeyboard {
[aTextField resignFirstResponder];
}</span></code></pre>
<pre class="lang-c prettyprint prettyprinted" style="border: 0px; line-height: 18px; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; text-align: left; vertical-align: baseline; width: auto;"><span style="background-color: white;"><span style="font-family: Times, Times New Roman, serif;">Method 2:</span></span></pre>
<pre class="lang-c prettyprint prettyprinted" style="border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; line-height: 18px; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; text-align: left; vertical-align: baseline; width: auto;"><span style="background-color: white;"><span style="font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; white-space: normal;">to make your </span><span style="border: 0px; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; margin: 0px; padding: 0px; vertical-align: baseline; white-space: normal;">UIView</span><span style="font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; white-space: normal;"> as an instance of UIControl and then link its "Touch Up Inside" event to (IBAction)</span><span style="border: 0px; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; margin: 0px; padding: 0px; vertical-align: baseline; white-space: normal;">dismissKeyboard:(id)sender</span><span style="font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; white-space: normal;"> method. </span></span></pre>
<pre class="lang-c prettyprint prettyprinted" style="border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; line-height: 18px; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; text-align: left; vertical-align: baseline; width: auto;"><pre class="lang-c prettyprint prettyprinted" style="border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto;"><code style="background-color: white; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; margin: 0px; padding: 0px; vertical-align: baseline;"><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">-</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="typ" style="border: 0px; color: #2b91af; margin: 0px; padding: 0px; vertical-align: baseline;">IBAction</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">)</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">dismissKeyboard</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">:(</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">id</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">)</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">sender </span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">{</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">[</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">aTextField resignFirstResponder</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">];</span><span class="pln" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">}</span></code></pre>
</pre>
<pre class="lang-c prettyprint prettyprinted" style="border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; line-height: 18px; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; text-align: left; vertical-align: baseline; width: auto;"><span style="background-color: white;"><span style="font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; white-space: normal;">
</span></span></pre>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-326345481932579870.post-84285491671984836312012-09-12T11:00:00.000+08:002012-09-12T11:35:58.026+08:00Show progress while uploading data to FacebookFacebook's SDK does not provide the delegate function to show the progress during uploading the data to Facebook, e.g. photo. Therefore, user has to create it by adding the following functions into FBRequest.h and FBRequest.m as well as your ViewController.<br />
<br />
In FBRequest.h, add the below function under FBRequestDelegate protocol:<br />
<br />
<span class="pun">-</span><span class="pln"> </span><span class="pun">(</span><span class="kwd">void</span><span class="pun">)</span><span class="pln">request</span><span class="pun">:(</span><span class="typ">FBRequest</span><span class="pln"> </span><span class="pun">*)</span><span class="pln">request didSendBodyData</span><span class="pun">:(</span><span class="typ">NSInteger</span><span class="pun">)</span><span class="pln">bytesWritten totalBytesWritten<span class="pun">:(</span><span class="typ">NSInteger</span><span class="pun">)</span><span class="pln">totalBytesWritten totalBytesExpectedToWrite</span><span class="pun">:(<span class="typ">NSInteger</span><span class="pun">)</span><span class="pln">totalBytesExpectedToWrite</span><span class="pun">;</span></span></span><br />
<br />
<br /><br />
<span class="pln"><span class="pun"><span class="pun">In FBRequest.m, add the below function:</span></span></span><br />
<br />
<span class="pln"><span class="pun"><span class="pun"><span class="pun">-</span><span class="pln"> </span><span class="pun">(</span><span class="kwd">void</span><span class="pun">)</span><span class="pln">connection</span><span class="pun">:(</span><span class="typ">NSURLConnection</span><span class="pln"> </span><span class="pun">*)</span><span class="pln">connection didSendBodyData</span><span class="pun">:(</span><span class="typ">NSInteger</span><span class="pun">)</span><span class="pln">bytesWritten totalBytesWritten</span><span class="pun">:(</span><span class="typ">NSInteger</span><span class="pun">)</span><span class="pln">totalBytesWritten totalBytesExpectedToWrite</span><span class="pun">:(</span><span class="typ">NSInteger</span><span class="pun">)</span><span class="pln">totalBytesExpectedToWrite </span></span></span></span><br />
<span class="pln"><span class="pun"><span class="pun"><span class="pln"></span><span class="pun">{</span><span class="pln"><br /> </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">([</span><span class="pln">_delegate respondsToSelector</span><span class="pun">:</span><span class="lit">@selector</span><span class="pun">(</span><span class="pln">request</span><span class="pun">:</span><span class="pln">didSendBodyData</span><span class="pun">:</span><span class="pln">totalBytesWritten</span><span class="pun">:</span><span class="pln">totalBytesExpectedToWrite</span><span class="pun">:)])</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br /> </span><span class="pun">[</span><span class="pln">_delegate request</span><span class="pun">:</span><span class="kwd">self</span><span class="pln"> didSendBodyData</span><span class="pun">:</span><span class="pln">bytesWritten totalBytesWritten</span><span class="pun">:</span><span class="pln">totalBytesWritten totalBytesExpectedToWrite</span><span class="pun">:</span><span class="pln">totalBytesExpectedToWrite</span><span class="pun">];</span><span class="pln"><br /> </span><span class="pun">}</span><span class="pln"> </span><span class="pun">}</span><span class="pln"></span></span></span></span><br />
<br />
<br /><br />
<span class="pln"><span class="pun"><span class="pun">In your ViewController, add the below function to implement the delegate function:</span></span></span><br />
<br />
<span class="pun">-</span><span class="pln"> </span><span class="pun">(</span><span class="kwd">void</span><span class="pun">)</span><span class="pln">request</span><span class="pun">:(</span><span class="typ">FBRequest</span><span class="pln"> </span><span class="pun">*)</span><span class="pln">request didSendBodyData</span><span class="pun">:(</span><span class="typ">NSInteger</span><span class="pun">)</span><span class="pln">bytesWritten totalBytesWritten</span><span class="pun">:(</span><span class="typ">NSInteger</span><span class="pun">)</span><span class="pln">totalBytesWritten totalBytesExpectedToWrite</span><span class="pun">:(</span><span class="typ">NSInteger</span><span class="pun">)</span><span class="pln">totalBytesExpectedToWrite </span><span class="pun">{</span><span class="pln"><br /> </span><span class="typ">NSLog</span><span class="pun">(@</span><span class="str">"%d bytes out of %d sent."</span><span class="pun">,</span><span class="pln"> totalBytesWritten</span><span class="pun">,</span><span class="pln"> totalBytesExpectedToWrite</span><span class="pun">);</span><span class="pln"> </span><span class="pun">}</span><span class="pln"> </span><br />
<br />
<br />
<span class="pln">Right now, your ViewController can receive the feedback from FBRequest when the data is being uploaded to Facebook.</span><br />
<br />Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-326345481932579870.post-36442711273689112952012-08-01T13:00:00.000+08:002012-09-12T11:02:29.688+08:00Public, Private, and Protected Instance Variables<div class="docText">
Classes can set instance variables as private, protected, and public. You use the compiler directives @private, @protected, and @public to declare the visiblity of instance variable. </div>
<div class="docText">
<br /></div>
<div class="docText">
The <span class="docEmphasis">public</span> directive allows any class access to the public variables.</div>
<div class="docText">
The <span class="docEmphasis">private</span> directive ensures private variables are only visible to the class which declares it. </div>
<div class="docText">
The <span class="docEmphasis">protected</span> directive ensures protected variables are only visible to the declaring class and its descendants. </div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-326345481932579870.post-68518578426580363932012-07-05T17:00:00.001+08:002012-09-12T11:05:59.599+08:00Alternative way to replace UIGetScreenImage()<span class="Apple-style-span" style="font-family: Menlo;">CGImageRef</span><span class="Apple-style-span" style="font-family: Menlo;"> </span><span class="Apple-style-span" style="font-family: Menlo;">screen =</span><span class="Apple-style-span" style="font-family: Menlo;"> </span><span class="Apple-style-span" style="font-family: Menlo;">UIGetScreenImage();</span><br />
<br />
The above code is one line of code to capture the screen, but Apple does not open the above API UIGetScreenImage() for the public app. i.e. fail to upload to Apple for approval. So the alternative way to capture screen and save it are listed as below.<br />
<br />
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
- (void)captureAndSaveImage</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
{ </div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
// Capture screen here... and cut the appropriate size for saving and uploading</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
UIGraphicsBeginImageContext(self.view.bounds.size);</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
UIGraphicsEndImageContext();</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
// crop the area you want </div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
CGRect rect;</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
rect = CGRectMake(0, 10, 300, 300); // whatever you want</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], rect);</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
UIImage *img = [UIImage imageWithCGImage:imageRef]; </div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
CGImageRelease(imageRef);</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
UIImageWriteToSavedPhotosAlbum(img, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
imageView.image = img; // show cropped image on the ImageView </div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
}</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<br /></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
// this is option to alert the image saving status</div>
<div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
{</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
UIAlertView *alert;</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
// Unable to save the image </div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
if (error)</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
alert = [[UIAlertView alloc] initWithTitle:@"Error" </div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
message:@"Unable to save image to Photo Album." </div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
delegate:self cancelButtonTitle:@"Dismiss" </div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
otherButtonTitles:nil];</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
else // All is well</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
alert = [[UIAlertView alloc] initWithTitle:@"Success" </div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
message:@"Image saved to Photo Album." </div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
delegate:self cancelButtonTitle:@"Ok" </div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
otherButtonTitles:nil];</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
[alert show];</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
[alert release];</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
}</div>
</div>
<div>
<br /></div>
<div>
<span class="Apple-style-span" style="font-family: Georgia, Times, serif; font-size: 13px; line-height: 19px;"><pre class="objc" style="border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; clear: none; font-family: monospace; font-size: 12px; line-height: 1.333; margin: 0px; overflow-x: visible; overflow-y: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline; white-space: pre; width: auto;"></pre>
</span></div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-326345481932579870.post-22665785917223366022012-07-03T18:24:00.003+08:002012-09-12T11:07:11.358+08:00Base64 encode/decode method//put it on the top of xxx.m<br />
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
static char base64EncodingTable[64] = {</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
};</div>
- (void)testBase64<br />
{<br />
<br />
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
NSString *testStr = @"000000";</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
NSString *encodedStr = [self base64StringFromData:testStr];</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
NSLog(@"%@", encodedStr);<br />
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
NSData *data = [self base64DataFromString:encodedStr];</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
NSString decodedStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];</div>
</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
NSLog(@"decoded string is %@ for %@", decodedStr, testStr);<br />
<br /></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
}</div>
<br />
<span class="Apple-style-span" style="color: #444444;"><br /></span>
// encode method<br />
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;">-(NSString *) base64StringFromData:(NSString *)str</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;">{</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> NSData* data=[str dataUsingEncoding:NSUTF8StringEncoding];</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> int length = str.length;</span><span class="Apple-style-span" style="color: #444444;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="color: #444444;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> unsigned long ixtext, lentext;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> long ctremaining;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> unsigned char input[3], output[4];</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> short i, charsonline = 0, ctcopy;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> const unsigned char *raw;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> NSMutableString *result;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="color: #444444;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> lentext = [data length]; </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> if (lentext < 1)</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> return @"";</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> result = [NSMutableString stringWithCapacity: lentext];</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> raw = [data bytes];</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> ixtext = 0; </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="color: #444444;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> while (true) {</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> ctremaining = lentext - ixtext;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> if (ctremaining <= 0) </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> break; </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> for (i = 0; i < 3; i++) { </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> unsigned long ix = ixtext + i;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> if (ix < lentext)</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> input[i] = raw[ix];</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> else</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> input[i] = 0;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> }</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> output[0] = (input[0] & 0xFC) >> 2;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> output[1] = ((input[0] & 0x03) << 4) | ((input[1] & 0xF0) >> 4);</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> output[2] = ((input[1] & 0x0F) << 2) | ((input[2] & 0xC0) >> 6);</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> output[3] = input[2] & 0x3F;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> ctcopy = 4;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> switch (ctremaining) {</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> case 1: </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> ctcopy = 2; </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> break;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> case 2: </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> ctcopy = 3; </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> break;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> }</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="color: #444444;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> for (i = 0; i < ctcopy; i++)</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> [result appendString: [NSString stringWithFormat: @"%c", base64EncodingTable[output[i]]]];</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="color: #444444;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> for (i = ctcopy; i < 4; i++)</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> [result appendString: @"="];</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="color: #444444;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> ixtext += 3;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> charsonline += 4;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="color: #444444;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> if ((length > 0) && (charsonline >= length))</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> charsonline = 0;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> } </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> return result;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;">}</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="color: #444444;"><br /></span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="color: #444444;"><br /></span>
<span class="Apple-style-span" style="color: #444444;">// decode method</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;">- (NSData *)base64DataFromString: (NSString *)string</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;">{</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> unsigned long ixtext, lentext;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> unsigned char ch, inbuf[4], outbuf[3];</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> short i, ixinbuf;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> Boolean flignore, flendtext = false;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> const unsigned char *tempcstring;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> NSMutableData *theData;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="color: #444444;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> if (string == nil)</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> {</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> return [NSData data];</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> }</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="color: #444444;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> ixtext = 0;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="color: #444444;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> tempcstring = (const unsigned char *)[string UTF8String];</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="color: #444444;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> lentext = [string length];</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="color: #444444;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> theData = [NSMutableData dataWithCapacity: lentext];</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="color: #444444;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> ixinbuf = 0;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="color: #444444;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> while (true)</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> {</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> if (ixtext >= lentext)</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> {</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> break;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> }</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="color: #444444;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> ch = tempcstring [ixtext++];</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="color: #444444;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> flignore = false;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="color: #444444;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> if ((ch >= 'A') && (ch <= 'Z'))</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> {</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> ch = ch - 'A';</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> }</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> else if ((ch >= 'a') && (ch <= 'z'))</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> {</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> ch = ch - 'a' + 26;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> }</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> else if ((ch >= '0') && (ch <= '9'))</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> {</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> ch = ch - '0' + 52;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> }</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> else if (ch == '+')</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> {</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> ch = 62;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> }</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> else if (ch == '=')</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> {</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> flendtext = true;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> }</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> else if (ch == '/')</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> {</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> ch = 63;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> }</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> else</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> {</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> flignore = true; </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> }</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="color: #444444;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> if (!flignore)</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> {</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> short ctcharsinbuf = 3;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> Boolean flbreak = false;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="color: #444444;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> if (flendtext)</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> {</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> if (ixinbuf == 0)</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> {</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> break;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> }</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="color: #444444;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> if ((ixinbuf == 1) || (ixinbuf == 2))</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> {</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> ctcharsinbuf = 1;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> }</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> else</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> {</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> ctcharsinbuf = 2;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> }</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="color: #444444;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> ixinbuf = 3;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="color: #444444;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> flbreak = true;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> }</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="color: #444444;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> inbuf [ixinbuf++] = ch;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="color: #444444;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> if (ixinbuf == 4)</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> {</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> ixinbuf = 0;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="color: #444444;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> outbuf[0] = (inbuf[0] << 2) | ((inbuf[1] & 0x30) >> 4);</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> outbuf[1] = ((inbuf[1] & 0x0F) << 4) | ((inbuf[2] & 0x3C) >> 2);</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> outbuf[2] = ((inbuf[2] & 0x03) << 6) | (inbuf[3] & 0x3F);</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="color: #444444;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> for (i = 0; i < ctcharsinbuf; i++)</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> {</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> [theData appendBytes: &outbuf[i] length: 1];</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> }</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> }</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="color: #444444;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> if (flbreak)</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> {</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> break;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> }</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> }</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> }</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="color: #444444;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;"> return theData;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="color: #444444;"><br /></span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="color: #444444;">}</span></div>
<div>
<br />
****************************************************</div>
<div>
Output in console:</div>
<div>
<br /></div>
<div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<b><span class="Apple-style-span" style="color: #444444;">Decoded string is MDAwMDAw for testStr 000000;</span></b></div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-326345481932579870.post-91708932932979258562012-06-26T11:27:00.002+08:002012-09-12T11:10:55.954+08:00php: get input and write text file, then returnPut the following codes in the server side to receive the inputs from Apps.<br />
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<br />
<?php</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
// assign the input to the variables</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
$method = $_POST['method'];</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
$name = $_POST['name']; // variable to be received by server<br />
$id = $_POST['userID']; // variable to be received by server</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
echo " user name: ".$name ." id: ". $id. " method: ". $method; // echo the received data to the Apps</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
// write text file with above two variables</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
$file = "file.txt";</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
$fh = fopen( $file, 'w' );</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
$carriageReturn = "\n";</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
fwrite( $fh, $method );</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
fwrite( $fh, $carriageReturn );</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
fwrite( $fh, $name );</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
fwrite( $fh, $carriageReturn );</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
fwrite( $fh, $id );</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
fclose( $fh );</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
?></div>
<div>
<br /></div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-326345481932579870.post-55261860443759865462012-06-26T11:25:00.000+08:002012-09-12T11:12:27.149+08:00php: return data in json<span class="Apple-style-span" style="font-family: Menlo;">In server side, the following code can return the data in JSON format to client(Apps).</span><br />
<br />
<span class="Apple-style-span" style="font-family: Menlo;"><?php</span><br />
<br />
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
$name = "Ben";</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
$id = "id1234";</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
$method = "get data";</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
// build result in json format</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
$arr = array("result" => "success",</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
"uid" => $id,</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
"data"=>array("name"=>$name, </div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
"id"=>$id, </div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
"method"=>$method </div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
)</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
);</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
echo json_encode($arr);</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
?></div>
<div>
<br /></div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-326345481932579870.post-59445743632889791992012-06-26T11:22:00.001+08:002012-09-12T11:14:37.963+08:00php: generates Token with random string<span class="Apple-style-span" style="font-family: Menlo;">The following code generate the random string with certain length to the client. It can be used to create the token and send to client's apps.</span><br />
<br />
<span class="Apple-style-span" style="font-family: Menlo;"><?php</span><br />
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
// generate random string</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
function random_gen($length)</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
{</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
$random= "";</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
srand((double)microtime()*1000000);</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
$char_list = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
$char_list .= "abcdefghijklmnopqrstuvwxyz";</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
$char_list .= "1234567890";</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
// Add the special characters to $char_list if needed</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
for($i = 0; $i < $length; $i++) </div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
{ </div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
$random .= substr($char_list,(rand()%(strlen($char_list))), 1); </div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
} </div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
return $random;</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
} </div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
$random_string = random_gen(30); //This will return a random 30 character string</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
echo "New Token: ".$random_string;</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
?></div>
<div>
<br /></div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-326345481932579870.post-53439342372991706432012-06-25T17:57:00.001+08:002012-09-12T11:25:29.963+08:00Distribute beta App over the air<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Now it is not necessary to send ipa file and distribution profile to beta tester for Apps testing. There is a distribution OTA method, the apps can be uploaded to server and let tester to install it from server.</span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">1. to create<span class="Apple-style-span" style="color: #3b3b3b; line-height: 18px;"> a provisioning distribution profile for Ad Hoc build with the selected iDevices (devices' UDID are registered in the portal).</span></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">2. in<span class="Apple-style-span" style="color: #3b3b3b; line-height: 18px;"> Xcode, associate this provisioning distribution profile with your build. I</span><span class="Apple-style-span" style="color: #3b3b3b; line-height: 18px;">n the</span><span class="Apple-style-span" style="color: #3b3b3b; line-height: 18px;"> </span><span class="Apple-style-span" style="color: #3b3b3b; line-height: 18px;"><span style="margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Code Signing</span></span><span class="Apple-style-span" style="color: #3b3b3b; line-height: 18px;"> </span><span class="Apple-style-span" style="color: #3b3b3b; line-height: 18px;">section choose the new</span><span class="Apple-style-span" style="color: #3b3b3b; line-height: 18px;"> </span><span class="Apple-style-span" style="color: #3b3b3b; line-height: 18px;"><span style="margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Provisioning Profile.</span></span></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="color: #3b3b3b; line-height: 18px;"><span style="margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">3. </span></span><span class="Apple-style-span" style="color: #3b3b3b; line-height: 18px;"><span style="margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Build and Archive.</span></span></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="color: #3b3b3b; line-height: 18px;"><span style="margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">4. </span></span><span class="Apple-style-span" style="color: #3b3b3b; line-height: 18px;">Click on the</span><span class="Apple-style-span" style="color: #3b3b3b; line-height: 18px;"> </span><span class="Apple-style-span" style="color: #3b3b3b; line-height: 18px;"><span style="margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Share</span></span><span class="Apple-style-span" style="color: #3b3b3b; line-height: 18px;"> </span><span class="Apple-style-span" style="color: #3b3b3b; line-height: 18px;">button, and </span></span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="color: #3b3b3b; line-height: 18px;">choose</span><span class="Apple-style-span" style="color: #3b3b3b; line-height: 18px;"> </span><span class="Apple-style-span" style="color: #3b3b3b; line-height: 18px;"><span style="margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Distribute for Enterprise</span></span><span class="Apple-style-span" style="color: #3b3b3b; line-height: 18px;"> </span><span class="Apple-style-span" style="color: #3b3b3b; line-height: 18px;">– fill in the URL to the location where you plan to host the application.</span></span><br />
<span class="Apple-style-span" style="color: #3b3b3b; line-height: 18px;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">5. Upload ipa, plist and icon files to the server you typed in step 4.</span></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="color: #3b3b3b; line-height: 18px;">6. B</span>uild the HTML to let iDevice to access and install the app.</span><br />
<br />
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "<a href="http://www.w3.org/TR/html4/loose.dtd">http://www.w3.org/TR/html4/loose.dtd</a>"> </div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<html></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<head> </div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<title>OTA Test App</title> </div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
</head> </div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<body></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<br><font size = "20">You are invited to test new app.</font></br></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<br><<font size="15"><a href="itms-services://?action=download-manifest&url=http://www.yourwebsite.com">Tap Here to Install the Application</a></font></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
</br> </div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
</body> </html><br />
<br />
You may refer to the below link.<br />
<a href="http://mobiledevelopertips.com/xcode/distribute-ad-hoc-applications-over-the-air-ota.html">http://mobiledevelopertips.com/xcode/distribute-ad-hoc-applications-over-the-air-ota.html</a></div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-326345481932579870.post-38728154837755836012012-06-18T11:38:00.001+08:002012-09-12T11:35:28.687+08:00No previous prototype for function<br />
<br />
<span class="Apple-style-span" style="font-family: 'Trebuchet MS', 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 13px; line-height: 12px;"></span><br />
<h1 itemprop="name" style="background-clip: initial; background-color: transparent; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; font-family: 'Trebuchet MS', 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 23px; font-weight: bold; line-height: 1.3; margin: 0px 0px 7px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">
<a class="question-hyperlink" href="http://stackoverflow.com/questions/7097660/how-to-handle-the-xcode-warning-no-previous-prototype-for-function" style="background-clip: initial; background-color: transparent; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; cursor: pointer; font-size: 23px; font-weight: bold; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none; vertical-align: baseline;">How to handle the Xcode warning “no previous prototype for function…”?</a></h1>
<div>
<br /></div>
<span class="Apple-style-span" style="border-collapse: collapse; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px;">Go to project's Build Settings. Search for "prototype". There is an option called "Missing Function Prototypes" under Apple LLVM complier 3.1 warning; disable it. </span><br />
<span class="Apple-style-span" style="border-collapse: collapse; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px;">Optionally, you can also do this to the specific target(s) in question.</span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-326345481932579870.post-73876056578010194282012-06-17T18:21:00.001+08:002012-09-12T11:27:42.425+08:00Label with dynamic heightThe below code creates the dynamic height to fit for the inputed text<br />
<br />
-(void)createDynamicHeight<br />
{<br />
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 300, 40)];</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
label.backgroundColor = [UIColor blackColor];</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
[self.view addSubview:label];</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
NSString *text = @"This is label with dynamic height";</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
label.text = text;</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
label.lineBreakMode = UILineBreakModeWordWrap;</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
// resize the height to fit the content</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
CGSize newLabelSize = [text sizeWithFont:label.font </div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
constrainedToSize:label.frame.size</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
lineBreakMode:UILineBreakModeWordWrap];</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
CGRect newFrame = instructions.frame;</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<br /></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
if (newLabelSize.height > 40) {</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
newFrame.size.height = newLabelSize.height;</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
} else {</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
newFrame.size.height = 40</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
}</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
label.frame = newFrame;</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
label.numberOfLines = 0;</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<br /></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
NSLog(@"Label height is %f", label.frame.size.height);</div>
<div>
}</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-326345481932579870.post-26245063731981232922012-06-14T15:57:00.001+08:002012-09-12T11:28:35.795+08:00Error: more than max 5 filtered album trying to register, this will failPer the subject, the following code may help to solve it.<br />
I tried in my project, it seems work.<br />
<br />
<span class="Apple-style-span" style="border-collapse: collapse; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px;"></span><br />
<pre class="default prettyprint" style="background-clip: initial; background-color: #eeeeee; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; margin: 0px 0px 10px; max-height: 600px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; vertical-align: baseline; width: auto;"><code style="background-clip: initial; background-color: #eeeeee; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><span class="pun" style="background-clip: initial; background-color: transparent; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">-</span><span class="pln" style="background-clip: initial; background-color: transparent; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"> </span><span class="pun" style="background-clip: initial; background-color: transparent; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">(</span><span class="kwd" style="background-clip: initial; background-color: transparent; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: darkblue; font-size: 14px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">void</span><span class="pun" style="background-clip: initial; background-color: transparent; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">)</span><span class="pln" style="background-clip: initial; background-color: transparent; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">viewDidAppear</span><span class="pun" style="background-clip: initial; background-color: transparent; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">:(</span><span class="pln" style="background-clip: initial; background-color: transparent; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">BOOL</span><span class="pun" style="background-clip: initial; background-color: transparent; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">)</span><span class="pln" style="background-clip: initial; background-color: transparent; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">animated</span><span class="pun" style="background-clip: initial; background-color: transparent; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">{</span><span class="pln" style="background-clip: initial; background-color: transparent; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"> </span><span class="pun" style="background-clip: initial; background-color: transparent; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">[</span><span class="kwd" style="background-clip: initial; background-color: transparent; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: darkblue; font-size: 14px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">super</span><span class="pln" style="background-clip: initial; background-color: transparent; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"> viewDidAppear</span><span class="pun" style="background-clip: initial; background-color: transparent; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">:</span><span class="pln" style="background-clip: initial; background-color: transparent; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">animated</span><span class="pun" style="background-clip: initial; background-color: transparent; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">];</span><span class="pln" style="background-clip: initial; background-color: transparent; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"> </span><span class="pun" style="background-clip: initial; background-color: transparent; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">[</span><span class="kwd" style="background-clip: initial; background-color: transparent; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: darkblue; font-size: 14px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">self</span><span class="pln" style="background-clip: initial; background-color: transparent; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"> setModalInPopover</span><span class="pun" style="background-clip: initial; background-color: transparent; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">:</span><span class="pln" style="background-clip: initial; background-color: transparent; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">YES</span><span class="pun" style="background-clip: initial; background-color: transparent; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">];</span><span class="pln" style="background-clip: initial; background-color: transparent; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"></span><span class="pun" style="background-clip: initial; background-color: transparent; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; color: black; font-size: 14px; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">}</span></code></pre>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-326345481932579870.post-71951314438822856982012-06-12T13:36:00.004+08:002012-09-12T11:29:47.381+08:00Limit the number of characters in UITextView<br />
#define MAX_LENGTH 50<br />
<br />
// UITextView delegate<br />
<br />
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { </div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
NSLog(@"type %d char", myTextView.text.length); </div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
if (myTextView.text.length >= MAX_LENGTH && range.length == 0)</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
{</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
NSLog(@"max length is reached");</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
return NO; // return NO to not change text</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
}</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
}</div>
Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-326345481932579870.post-7455469994991553112012-06-05T18:34:00.001+08:002012-09-12T11:30:37.023+08:00Limit the number of lines in UITextView<br />
<span class="Apple-style-span" style="background-color: white;"><br /></span>
<br />
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="background-color: white;">- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="background-color: white;">{</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="background-color: white;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="background-color: white;"> // limit the number of lines in textview</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="background-color: white;"> NSString* newText = [mytextView.text stringByReplacingCharactersInRange:range withString:text];</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="background-color: white;"><br /></span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="background-color: white;"> // pretend there's more vertical space to get that extra line to check on</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="background-color: white;"> CGSize tallerSize = CGSizeMake(mytextView.frame.size.width-15, mytextView.frame.size.height*2); </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="background-color: white;"><br /></span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="background-color: white;"> CGSize newSize = [newText sizeWithFont:mytextView.font constrainedToSize:tallerSize lineBreakMode:UILineBreakModeWordWrap];</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="background-color: white;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="background-color: white;"> if (newSize.height > mytextView.frame.size.height)</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="background-color: white;"> {</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="background-color: white;"> NSLog(@"two lines are full");</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="background-color: white;"> return NO;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="background-color: white;"> }</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="background-color: white;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="background-color: white;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="background-color: white;"> // dismiss keyboard and send comment</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="background-color: white;"> if([text isEqualToString:@"\n"]) {</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="background-color: white;"> [mytextView resignFirstResponder];</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="background-color: white;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="background-color: white;"> return NO;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="background-color: white;"> }</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px; min-height: 13px;">
<span class="Apple-style-span" style="background-color: white;"> </span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="background-color: white;"> return YES;</span></div>
<div style="font-family: Menlo; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin: 0px;">
<span class="Apple-style-span" style="background-color: white;">}</span></div>
<div>
<br /></div>
Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-326345481932579870.post-26560040489197242732012-05-15T22:42:00.002+08:002012-09-12T11:35:20.502+08:00Hide StatusBar, TabBar, NavigationBar<span style="background-color: white;"><span class="Apple-style-span" style="border-collapse: collapse; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px;"></span><br /></span>
<div style="background-clip: initial; background-color: transparent; background-origin: initial; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; clear: both; font-size: 14px; margin: 0px 0px 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline; word-wrap: break-word;">
<span style="background-color: white;">1. To hide the status bar:</span><br />
<br />
[[UIApplication shareApplication] setStatusBarHidden:YES];<br />
<br />
<br />
2. To hide the navigation bar:<br />
<br />
self.navigationController.navigationBarHidden = YES;<br />
<br />
<br />
3. To hide the tab bar:<br />
<br />
MyController *myController = [[MyController alloc] init ];<br />
myController.hidesBottomBarWhenPushed = YES;<br />
[self.navigationController pushViewController:myController animated:YES];<br />
[myController release];</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-326345481932579870.post-7721161119083124812012-04-02T17:02:00.000+08:002012-04-02T17:02:00.845+08:00New app - PhotoUploads (Full version)Full version of PhotoUploads is available in App Store. It lets you to upload unlimited photos to Facebook, Flickr, dropbox and own server.<br />
<br />
The php script is included in the app for you to set up the server.<br />
<br />
<a href="http://itunes.apple.com/us/app/photouploads/id505900653?mt=8">http://itunes.apple.com/us/app/photouploads/id505900653?mt=8</a><br />
<div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-qCFkLw26c40/T3lqpCjzrlI/AAAAAAAAAC4/0D1_qTyThKw/s1600/3.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="320" src="http://1.bp.blogspot.com/-qCFkLw26c40/T3lqpCjzrlI/AAAAAAAAAC4/0D1_qTyThKw/s320/3.png" width="213" /></a></div><a href="http://3.bp.blogspot.com/-H7D1IGaIy2I/T3lppIs7bZI/AAAAAAAAACY/IVEqAZsY-jU/s1600/2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="320" src="http://3.bp.blogspot.com/-H7D1IGaIy2I/T3lppIs7bZI/AAAAAAAAACY/IVEqAZsY-jU/s320/2.png" width="213" /></a><br />
<a href="http://4.bp.blogspot.com/-fTR5melGiRQ/T3lptumADII/AAAAAAAAACg/2C1bEjOiVO0/s1600/1.png" imageanchor="1" style="clear: left; display: inline !important; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="320" src="http://4.bp.blogspot.com/-fTR5melGiRQ/T3lptumADII/AAAAAAAAACg/2C1bEjOiVO0/s320/1.png" width="213" /></a><a href="http://3.bp.blogspot.com/-y66KZ1w4jBw/T3lp4Xy3DYI/AAAAAAAAACw/SKupYRfGKb4/s1600/4.png" imageanchor="1" style="clear: left; display: inline !important; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="320" src="http://3.bp.blogspot.com/-y66KZ1w4jBw/T3lp4Xy3DYI/AAAAAAAAACw/SKupYRfGKb4/s320/4.png" width="213" /></a><br />
<br />
<br />
<span id="goog_2078713716"></span><span id="goog_2078713717"></span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-326345481932579870.post-43042928552353281712012-03-30T21:46:00.007+08:002012-03-30T22:55:19.127+08:00Autorelease, release, retain<span class="Apple-style-span" style="font-family: inherit;"><span class="Apple-style-span" style="color: #242424; line-height: 22px;">在Objective-C中所有的物件都是指標,</span><span class="Apple-style-span" style="color: #242424; line-height: 22px;">當我們建立一個物件時(</span><span class="Apple-style-span" style="color: #333333; line-height: 18px;">由 alloc、new、copy 產生出來或是使用retain</span><span class="Apple-style-span" style="color: #333333; line-height: 18px;">來取得</span><span class="Apple-style-span" style="color: #333333; line-height: 18px;">從其他來源獲得的</span><span class="Apple-style-span" style="color: #333333; line-height: 18px;">物件</span><span class="Apple-style-span" style="color: #333333; line-height: 18px;">)</span><span class="Apple-style-span" style="color: #242424; line-height: 22px;">,我們不但配置了記憶體,同時也讓該物件的指標指向這個記憶體位址。 Objective-C使用reference counting的方式作為記憶體管理的機制,</span><span class="Apple-style-span" style="color: #333333; line-height: 18px;">Reference Counting 的運作是基於 ownership。當程式要使用物件時,必須取得物件的 ownership,一個物件可以有很多 owner;而當程式不再使用物件時,則需要放棄 ownership。直到物件沒有任何 owner 時,物件就會自動被 dealloc。</span></span><br />
<span class="Apple-style-span" style="font-family: inherit;"><span class="Apple-style-span" style="color: #333333; line-height: 18px;">當</span><span class="Apple-style-span" style="color: #242424; line-height: 22px;">物件第一次被建立時,只有一個owner的指標指向它的記憶體位址,所以它的reference count為1。若有新owner的指標指向該記憶體,它的reference count便會加1。相反的,如果我們不再需要這個指標,而將它release,該物件的reference count就會減1。當該物件的reference count變為零時,代表沒有指標指向它了,</span><span class="Apple-style-span" style="color: #242424; line-height: 22px;">該物件的dealloc函式就會自動被呼叫,這時寫在dealloc裡的那些release指令就會一起被執行了,</span><span class="Apple-style-span" style="color: #242424; line-height: 22px;">這塊記憶體就會被釋放掉。</span></span><br />
<span class="Apple-style-span" style="color: #242424; font-family: inherit; line-height: 22px;"><br />
</span><br />
<span class="Apple-style-span" style="color: #242424; font-family: inherit; line-height: 22px;">在Objective-C建立物件有兩種方法,一種是手動配置記憶體並初始化該物件:</span><br />
<span class="Apple-style-span" style="color: #242424; font-family: inherit; line-height: 22px;"><br />
</span><br />
<span class="Apple-style-span" style="color: #242424; font-family: inherit; line-height: 22px;">NSString *string = [[NSString alloc] init];</span><br />
<span class="Apple-style-span" style="color: #242424; font-family: inherit; line-height: 22px;">用這種方式宣告的物件,當我們不再需要使用時,必需手動呼叫release方法來釋放它。</span><br />
<span class="Apple-style-span" style="color: #242424; font-family: inherit; line-height: 22px;"><strong><br />
</strong></span><br />
<span class="Apple-style-span" style="color: #242424; font-family: inherit; line-height: 22px;">另一種方法則是呼叫該類別的類別方法(Class method)直接建立該物件:</span><br />
<span class="Apple-style-span" style="color: #242424; font-family: inherit; line-height: 22px;"><br />
</span><br />
<span class="Apple-style-span" style="color: #242424; font-family: inherit; line-height: 22px;">NSString *string = [NSString stringWithFormat:@"test string"];</span><br />
<span class="Apple-style-span" style="font-family: inherit;"><span class="Apple-style-span" style="color: #242424; line-height: 22px;">這類方法所建立的物件我們不需要手動release它,當它被建立的同時,它也會被丟進一個叫做autorelease pool的「池子」裡。每當程式主要的loop執行完一次,就會檢查autorelease pool裡的物件是否還會被使用到,如果會就留著;如果不會就把它清掉。</span><span class="Apple-style-span" style="color: #242424; line-height: 22px;">這種會把物件丟進autorelease pool的類別方法有個特點,就是他們的名稱開頭都會是該類別的字串。比如NSString,類別方法中開頭是stringXXX的,就會把建立的物件丟入autorelease pool。</span></span><br />
<span class="Apple-style-span" style="color: #242424; font-family: inherit; line-height: 22px;"><br />
</span><br />
<span class="Apple-style-span" style="color: #242424; line-height: 22px;"><span class="Apple-style-span" style="color: #222222; font-family: inherit; line-height: 27px;">要特別注意的是,autorelease跟release不同,release會馬上在執行後把retain count減1,而autorelease則是<strong style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-weight: bold; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">待會</strong>才會減1。另外,一但你把物件設定為autorelease之後,這個東西基本上就不算是你管的,你之後就不需要也不應該再去對它做release的動作了。</span></span><br />
<span class="Apple-style-span" style="color: #242424; line-height: 22px;"><span class="Apple-style-span" style="color: #222222; font-family: inherit; line-height: 27px;"><br />
</span></span><br />
<span class="Apple-style-span" style="border-collapse: collapse; color: #93a1a1; font-family: inherit; line-height: 18px; white-space: pre;"><span class="line" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #93a1a1; font-style: normal !important; font-weight: normal !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><span class="k" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #cb4b16; font-style: normal !important; font-weight: normal !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">- </span><span class="p" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #93a1a1; font-style: normal !important; font-weight: normal !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">(</span><span class="n" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #268bd2; font-style: normal !important; font-weight: normal !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">NSString</span> <span class="o" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #93a1a1; font-style: normal !important; font-weight: bold !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">*</span><span class="p" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #93a1a1; font-style: normal !important; font-weight: normal !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">)</span> <span class="nf" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #268bd2; font-style: normal !important; font-weight: bold !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">getBookTitle </span></span><span class="line" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #93a1a1; font-style: normal !important; font-weight: normal !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><span class="p" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #93a1a1; font-style: normal !important; font-weight: normal !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">{</span> </span><span class="line" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #93a1a1; font-style: normal !important; font-weight: normal !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"> </span></span><br />
<span class="Apple-style-span" style="border-collapse: collapse; color: #93a1a1; font-family: inherit; line-height: 18px; white-space: pre;"><span class="line" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #93a1a1; font-style: normal !important; font-weight: normal !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><span class="n" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #268bd2; font-style: normal !important; font-weight: normal !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">NSString</span> <span class="o" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #93a1a1; font-style: normal !important; font-weight: bold !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">*</span><span class="n" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #268bd2; font-style: normal !important; font-weight: normal !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">name</span> <span class="o" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #93a1a1; font-style: normal !important; font-weight: bold !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">=</span> <span class="p" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #93a1a1; font-style: normal !important; font-weight: normal !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">[[</span><span class="n" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #268bd2; font-style: normal !important; font-weight: normal !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">NSString</span> <span class="n" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #268bd2; font-style: normal !important; font-weight: normal !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">alloc</span><span class="p" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #93a1a1; font-style: normal !important; font-weight: normal !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">]</span> <span class="nl" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #859900; font-style: normal !important; font-weight: normal !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">initWithString:</span><span class="s" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #2aa198; font-style: normal !important; font-weight: normal !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">@"This is a book"</span><span class="p" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #93a1a1; font-style: normal !important; font-weight: normal !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">];</span> </span><span class="line" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #93a1a1; font-style: normal !important; font-weight: normal !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"> </span></span><br />
<span class="Apple-style-span" style="border-collapse: collapse; color: #93a1a1; font-family: inherit; line-height: 18px; white-space: pre;"><span class="line" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #93a1a1; font-style: normal !important; font-weight: normal !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><span class="p" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #93a1a1; font-style: normal !important; font-weight: normal !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">[</span><span class="n" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #268bd2; font-style: normal !important; font-weight: normal !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">name</span> auto<span class="n" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #268bd2; font-style: normal !important; font-weight: normal !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">release</span><span class="p" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #93a1a1; font-style: normal !important; font-weight: normal !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">];</span> </span><span class="line" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #93a1a1; font-style: normal !important; font-weight: normal !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"> </span></span><br />
<span class="Apple-style-span" style="border-collapse: collapse; color: #93a1a1; font-family: inherit; line-height: 18px; white-space: pre;"><span class="line" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #93a1a1; font-style: normal !important; font-weight: normal !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><span class="k" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #cb4b16; font-style: normal !important; font-weight: normal !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">return</span> <span class="n" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #268bd2; font-style: normal !important; font-weight: normal !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">name</span><span class="p" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #93a1a1; font-style: normal !important; font-weight: normal !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">;</span> </span><span class="line" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #93a1a1; font-style: normal !important; font-weight: normal !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><span class="p" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #93a1a1; font-style: normal !important; font-weight: normal !important; font: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">}</span></span></span><br />
<span class="Apple-style-span" style="color: #242424; font-family: inherit; line-height: 22px;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: inherit;"><span class="Apple-style-span" style="color: #242424; line-height: 22px;"><span class="Apple-style-span" style="color: #404040;">以上的code,因為name這個方法需要回傳值,如果第4行的[name autorelease]寫成了[name release],因為太早release掉name後,name就不會正確回傳了。不加上的話又會造成記憶體的泄漏(leaked)。所以這時候使用了autorelease就是正確的作法。</span></span><span class="Apple-style-span" style="color: #404040; line-height: 22px;">上面的程式碼第2行常常會和autorelease合併簡寫為類似[[[NSString alloc] init] autorelease],或是把第3和4行合併簡寫為return [name autorelease]。</span></span><br />
<span class="Apple-style-span" style="color: #242424; font-family: inherit; line-height: 22px;"><br />
</span><br />
<span class="Apple-style-span" style="color: #242424; font-family: inherit;"></span><br />
<div style="line-height: 22px;"><span class="Apple-style-span" style="font-family: inherit;">這裡提供幾個基本的原則,希望對還不熟悉記憶體管理的朋友們有些幫助:</span></div><div><span class="Apple-style-span" style="font-family: inherit;"><br />
</span><br />
<ol style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; line-height: 22px; list-style-image: initial; list-style-position: initial; list-style-type: none; margin-bottom: 10px; margin-left: 0.5em; margin-right: 0px; margin-top: 10px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;"><li style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; line-height: 16px; list-style-image: initial; list-style-position: initial; list-style-type: decimal; margin-bottom: 4px; margin-left: 20px; margin-right: 0px; margin-top: 4px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span class="Apple-style-span" style="font-family: inherit;">如果是自已alloc或者retain的物件,最後一定要release掉。</span></li>
</ol><ol style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; line-height: 22px; list-style-image: initial; list-style-position: initial; list-style-type: none; margin-bottom: 10px; margin-left: 0.5em; margin-right: 0px; margin-top: 10px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;"><li style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; line-height: 16px; list-style-image: initial; list-style-position: initial; list-style-type: decimal; margin-bottom: 4px; margin-left: 20px; margin-right: 0px; margin-top: 4px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span class="Apple-style-span" style="font-family: inherit;">用類別方法(Class method)建立的物件會被丟入autorelease pool,不需要手動釋放記憶體。</span></li>
</ol><span class="Apple-style-span" style="font-family: inherit;"><br />
</span><br />
<div><span class="Apple-style-span" style="font-family: inherit; line-height: 16px;"><br />
</span></div><div><span class="Apple-style-span" style="font-family: inherit; line-height: 16px;">Reference:</span></div></div><div><span class="Apple-style-span" style="font-family: inherit; line-height: 16px;">http://bonjouryentinglai.wordpress.com/2010/02/10/objective-c-隨手筆記-ii-記憶體管理</span><br />
<span class="Apple-style-span" style="font-family: inherit; line-height: 16px;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: inherit; line-height: 16px;">http://marcelsite.heroku.com/posts/5-iPhone-s-alloc-init-new-retain-release-autorelease-copy-</span><br />
<span class="Apple-style-span" style="font-family: inherit; line-height: 16px;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: inherit; line-height: 16px;">http://log.bcse.tw/2011/05/ios-programming-tips-3.html</span></div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-326345481932579870.post-25249297337725974872012-03-26T12:00:00.002+08:002012-04-02T17:03:36.191+08:00New app - PhotoUploads Lite (Free version)New app "PhotoUploads Lite" is available in App Store.<br />
<br />
This app lets you to upload the photos to Facebook, Flickr and Dropbox, and view the photos in the account.<br />
<br />
<a href="http://itunes.apple.com/us/app/photouploads-lite/id511228591?mt=8">http://itunes.apple.com/us/app/photouploads-lite/id511228591?mt=8</a><br />
<br />
<a href="http://3.bp.blogspot.com/-N9G7HGCaa4U/T2_pOssTAUI/AAAAAAAAABw/7Ok1KQaLkUs/s1600/1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="320" src="http://3.bp.blogspot.com/-N9G7HGCaa4U/T2_pOssTAUI/AAAAAAAAABw/7Ok1KQaLkUs/s320/1.png" width="213" /> <span class="Apple-style-span" style="-webkit-text-decorations-in-effect: none; color: black;"></span></a><a href="http://2.bp.blogspot.com/-AaKR8INsWmo/T2_pTE4eO7I/AAAAAAAAACA/JkjZ-GcOZxo/s1600/3.png" imageanchor="1" style="clear: left; display: inline !important; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="320" src="http://2.bp.blogspot.com/-AaKR8INsWmo/T2_pTE4eO7I/AAAAAAAAACA/JkjZ-GcOZxo/s320/3.png" width="213" /></a><a href="http://2.bp.blogspot.com/-QnuaFmHpIdw/T3loVyGlh_I/AAAAAAAAACI/zadHfivigBE/s1600/0.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="320" src="http://2.bp.blogspot.com/-QnuaFmHpIdw/T3loVyGlh_I/AAAAAAAAACI/zadHfivigBE/s320/0.png" width="213" /></a>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-326345481932579870.post-89952408243029334642012-03-25T14:12:00.000+08:002012-03-25T14:12:43.831+08:00To ping the server to determine if it is reachableHere is the method to ping if the server is reachable.<br />
<br />
<br />
<div style="font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;">- (<span style="color: #cc00a1;">BOOL</span>)canPingServer {</div><div style="font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 13.0px;"> </div><div style="font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;"> <span style="color: #7d18ab;">NSString</span> *serverAddress = <span style="color: #408389;">urlField</span>.<span style="color: #7d18ab;">text</span>;</div><div style="font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 13.0px;"> </div><div style="font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;"> <span style="color: #480083;">NSLog</span>(<span style="color: #e10000;">@"ping domain: %@"</span>, serverAddress);</div><div style="font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 13.0px;"> </div><div style="font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;"> <span style="color: #408389;">Reachability</span>* reachability = [[<span style="color: #408389;">Reachability</span> <span style="color: #255b5f;">reachabilityWithHostName</span>: serverAddress] <span style="color: #480083;">retain</span>];</div><div style="font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;"> <span style="color: #408389;">NetworkStatus</span> netStatus = [reachability <span style="color: #255b5f;">currentReachabilityStatus</span>];</div><div style="font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 13.0px;"> </div><div style="font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;"> <span style="color: #cc00a1;">if</span> ((netStatus == <span style="color: #255b5f;">ReachableViaWWAN</span>) || (netStatus == <span style="color: #255b5f;">ReachableViaWiFi</span>)) </div><div style="font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;"> <span style="color: #cc00a1;">return</span> <span style="color: #cc00a1;">YES</span>;</div><div style="font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;"> <span style="color: #cc00a1;">else</span> </div><div style="font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;"> <span style="color: #cc00a1;">return</span> <span style="color: #cc00a1;">NO</span>;</div><div style="font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 13.0px;"> </div><div style="font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;">}</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-326345481932579870.post-29379294316819579132012-03-24T23:30:00.000+08:002012-03-24T23:30:14.748+08:00Dismiss UIAlertView without clicking the buttonIf need to dismiss the UIAlertView without clicking the button, we could use the below method.<br />
<br />
<div style="color: #480083; font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;"><span style="color: black;"><br />
</span></div><div style="color: #480083; font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;"><span style="color: black;"><br />
</span></div><div style="color: #480083; font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;"><span style="color: black;">-(void) showAlert {</span></div><div style="font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"></div><div style="font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"></div><div style="color: #e10000; font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span style="color: #408389;">UIAlertView *alert</span><span style="color: black;"> = [[</span><span style="color: #7d18ab;">UIAlertView</span><span style="color: black;"> </span><span style="color: #480083;">alloc</span><span style="color: black;">] </span><span style="color: #480083;">initWithTitle</span><span style="color: black;">:</span>@"Connecting to server"<span style="color: black;"> </span><span style="color: #480083;">message</span><span style="color: black;">:</span>@"Please wait ..."<span style="color: black;"> </span><span class="Apple-style-span" style="color: black;"><span style="color: #480083;">delegate</span>:<span style="color: #cc00a1;">self</span> <span style="color: #480083;">cancelButtonTitle</span>:<span style="color: #cc00a1;">nil</span> <span style="color: #480083;">otherButtonTitles</span>: <span style="color: #cc00a1;">nil</span>];</span></div><div style="color: #e10000; font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="color: black;">[alert show];</span></div><div style="color: #e10000; font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="color: black;">}</span></div><div style="color: #e10000; font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="color: black;"><br />
</span></div><div style="color: #e10000; font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="color: black;">-(void) anotherMethod {</span></div><div style="font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">yourCode...add the below method</div><div style="font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"></div><div style="font-family: Times; font-size: medium; font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"></div><div style="color: #480083; font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;"><span style="color: black;">[a</span><span style="color: #408389;">lert</span><span style="color: black;"> </span>dismissWithClickedButtonIndex<span style="color: black;">:</span><span style="color: #4300dc;">0</span><span style="color: black;"> </span>animated<span style="color: black;">:</span><span style="color: #cc00a1;">TRUE</span><span style="color: black;">];</span></div><div style="font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;">[a<span style="color: #408389;">lert</span> <span style="color: #480083;">release</span>];</div><div>}</div><br />
<br />
<div style="font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br />
</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-326345481932579870.post-61741923185059704032012-03-17T18:24:00.000+08:002012-03-17T18:24:15.433+08:00NSMutableDictionary - write and read<div style="color: #e10000; font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;"><span style="color: black;">Write value for key:</span></div><div style="color: #e10000; font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;"><span style="color: black;">[</span><span style="color: #408389;">progressDict</span><span style="color: black;"> </span><span style="color: #480083;">setObject</span><span style="color: black;">:</span>@"Uploading ..."<span style="color: black;"> </span><span style="color: #480083;">forKey</span><span style="color: black;">:</span>@"status"<span style="color: black;">];</span></div><div style="color: #480083; font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;"><span style="color: black;">[</span><span style="color: #408389;">progressDict</span><span style="color: black;"> </span>setObject<span style="color: black;">:[</span><span style="color: #7d18ab;">NSNumber</span><span style="color: black;"> </span>numberWithInt<span style="color: black;">:i] </span>forKey<span style="color: black;">:</span><span style="color: #e10000;">@"progress"</span><span style="color: black;">];</span></div><div style="color: #480083; font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;"><span style="color: black;"><br />
</span></div><div style="font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Read value for key:</div><div style="color: #480083; font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;"><span style="color: black;"></span></div><div style="color: #e10000; font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;"><span style="color: #480083;">NSLog</span><span style="color: black;">(</span>@"key is status, value is %@"<span style="color: black;">,[dict </span><span style="color: #480083;">objectForKey</span><span style="color: black;">:</span>@"status"<span style="color: black;">]);</span></div><div style="color: #e10000; font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;"><span style="color: #480083;">NSLog</span><span style="color: black;">(</span>@"key is progress, value is %@"<span style="color: black;">,[dict </span><span style="color: #480083;">objectForKey</span><span style="color: black;">:</span>@"progress"<span style="color: black;">] );</span></div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-326345481932579870.post-29060910278439918032012-03-03T13:55:00.001+08:002012-03-03T15:24:23.646+08:00Grab the image Data from web or mainBundle<div style="font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;">-(<span style="color: #cc00a1;">void</span>) grabImagefromURL</div><div style="font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;">{</div><div style="color: #e10000; font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;"><span style="color: black;"> </span><span style="color: #7d18ab;">NSURL</span><span style="color: black;"> *url = [</span><span style="color: #7d18ab;">NSURL</span><span style="color: black;"> </span><span style="color: #480083;">URLWithString</span><span style="color: black;">:</span>@"http://cultofmac.cultofmaccom.netdna-cdn.com/wp-content/uploads/2010/01/apple-vs-google_2.jpg"<span style="color: black;">];</span></div><div style="color: #480083; font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;"><span style="color: black;"> </span><span style="color: #408389;">imageData</span><span style="color: black;"> = [</span><span style="color: #7d18ab;">NSData</span><span style="color: black;"> </span>dataWithContentsOfURL<span style="color: black;">:url];</span></div><div style="font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;"> <span style="color: #7d18ab;">UIImage</span> *image = [[<span style="color: #7d18ab;">UIImage</span> <span style="color: #480083;">alloc</span>] <span style="color: #480083;">initWithData</span>:<span style="color: #408389;">imageData</span>];</div><div style="font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;"> <span style="color: #408389;">myImageView</span>.<span style="color: #7d18ab;">image</span> = image;</div><div style="font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;"> [image <span style="color: #480083;">release</span>];</div><div style="font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 13.0px;"> </div><div style="font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;">}</div><div style="font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;"><br />
</div><div style="font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;">- (void) grabImagefromFile</div><div style="font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;">{</div><div style="font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;"><br />
</div><div style="font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;"></div><div style="color: #480083; font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;"><span style="color: #7d18ab;"> NSString</span><span style="color: black;"> *filePath = [[</span><span style="color: #7d18ab;">NSBundle</span><span style="color: black;"> </span>mainBundle<span style="color: black;">] </span>pathForResource<span style="color: black;">:</span><span style="color: #e10000;">@"lion"</span><span style="color: black;"> </span>ofType<span style="color: black;">:</span><span style="color: #e10000;">@"jpg"</span><span style="color: black;">]; </span></div><div style="font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;"><br />
<div style="color: #480083; font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;"><span style="color: black;"> </span><span style="color: #7d18ab;">UIImage</span><span style="color: black;"> *image = [</span><span style="color: #7d18ab;">UIImage</span><span style="color: black;"> </span>imageWithContentsOfFile<span style="color: black;">:filePath];</span></div></div><div style="font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;"> <span style="color: #7d18ab;">UIImageView</span> *imageView = [[<span style="color: #7d18ab;">UIImageView</span> <span style="color: #480083;">alloc</span>] <span style="color: #480083;">initWithImage</span>:img];</div><div style="font: 11.0px Menlo; margin: 0.0px 0.0px 0.0px 0.0px;"> [<span style="color: #cc00a1;">self</span>.<span style="color: #7d18ab;">view</span> <span style="color: #480083;">addSubview</span>:imageView];</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-326345481932579870.post-49359155304232521072012-03-03T13:18:00.000+08:002012-03-03T13:18:43.800+08:00Set multi-lines in the labelSet the lines = 0 in the label tab, then the text can be shown as the multi-line in the UILabel. Actually it can be done in code too.<br />
<br />
<div class="separator" style="clear: both; text-align: left;"><a href="http://2.bp.blogspot.com/-rFDuJ10lGac/T1Go7vkcXGI/AAAAAAAAABo/enEZP95jnkg/s1600/Screen+Shot+2012-03-03+at+1.10.07+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="216" src="http://2.bp.blogspot.com/-rFDuJ10lGac/T1Go7vkcXGI/AAAAAAAAABo/enEZP95jnkg/s320/Screen+Shot+2012-03-03+at+1.10.07+PM.png" width="320" /></a></div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-326345481932579870.post-91436705720989759592012-03-03T13:14:00.002+08:002012-03-03T13:24:20.838+08:00Mac - Screen capture<span class="Apple-style-span" style="color: #333333; font-family: arial, helvetica, clean, sans-serif; font-size: 13px; line-height: 16px;"><br />
</span><span class="Apple-style-span" style="color: #333333; font-family: arial, helvetica, clean, sans-serif; font-size: 13px; line-height: 16px;">Command +Shift+3</span><span class="Apple-style-span" style="color: #333333; font-family: arial, helvetica, clean, sans-serif; font-size: 13px; line-height: 16px;"> </span><span class="Apple-style-span" style="color: #333333; font-family: arial, helvetica, clean, sans-serif; font-size: 13px; line-height: 16px;"><br />
</span><span class="Apple-style-span" style="color: #333333; font-family: arial, helvetica, clean, sans-serif; font-size: 13px; line-height: 16px;">It captures entire screen and saves it in the desktop.</span><span class="Apple-style-span" style="color: #333333; font-family: arial, helvetica, clean, sans-serif; font-size: 13px; line-height: 16px;"><br />
</span><span class="Apple-style-span" style="color: #333333; font-family: arial, helvetica, clean, sans-serif; font-size: 13px; line-height: 16px;"></span><span class="Apple-style-span" style="color: #333333; font-family: arial, helvetica, clean, sans-serif; font-size: 13px; line-height: 16px;"> </span><span class="Apple-style-span" style="color: #333333; font-family: arial, helvetica, clean, sans-serif; font-size: 13px; line-height: 16px;"><br />
</span><span class="Apple-style-span" style="color: #333333; font-family: arial, helvetica, clean, sans-serif; font-size: 13px; line-height: 16px;">Command +Shift+4</span><span class="Apple-style-span" style="color: #333333; font-family: arial, helvetica, clean, sans-serif; font-size: 13px; line-height: 16px;"> </span><span class="Apple-style-span" style="color: #333333; font-family: arial, helvetica, clean, sans-serif; font-size: 13px; line-height: 16px;"><br />
</span><span class="Apple-style-span" style="color: #333333; font-family: arial, helvetica, clean, sans-serif; font-size: 13px; line-height: 16px;">Use the mouse to select a specific area of the screen for capture saves it in the desktop, press ESC to dismiss.</span><span class="Apple-style-span" style="color: #333333; font-family: arial, helvetica, clean, sans-serif;"><span class="Apple-style-span" style="font-size: x-small;"><span class="Apple-style-span" style="line-height: 16px;"><br />
</span></span> </span><br />
<span class="Apple-style-span" style="color: #333333; font-family: arial, helvetica, clean, sans-serif; font-size: 13px; line-height: 16px;"><br />
</span><br />
<span class="Apple-style-span" style="color: #333333; font-family: arial, helvetica, clean, sans-serif; font-size: 13px; line-height: 16px;">Cmd+Ctrl+Shift 3</span><br />
<span class="Apple-style-span" style="color: #333333; font-family: arial, helvetica, clean, sans-serif; font-size: 13px; line-height: 16px;">It captures the screenshot and keep it in clipboard</span><br />
<span class="Apple-style-span" style="color: #333333; font-family: arial, helvetica, clean, sans-serif; font-size: x-small;"><span class="Apple-style-span" style="line-height: 16px;"><br />
</span></span><br />
<span class="Apple-style-span" style="color: #333333; font-family: arial, helvetica, clean, sans-serif; font-size: 13px; line-height: 16px;">Cmd+Ctrl+Shift 4</span><br />
<span class="Apple-style-span" style="color: #333333; font-family: arial, helvetica, clean, sans-serif; font-size: 13px; line-height: 16px;">It captures the selected screenshot and keep it in clipboard</span>Unknownnoreply@blogger.com0