tag:blogger.com,1999:blog-79496213055728901182024-03-05T23:08:00.335+08:00iBombSiteNoyhttp://www.blogger.com/profile/02645704038220895675noreply@blogger.comBlogger8125tag:blogger.com,1999:blog-7949621305572890118.post-82011526953166991482012-10-10T17:11:00.000+08:002012-10-10T18:14:53.198+08:00How iOS 6 Messed Up Pre-iOS 6 ApplicationsProbably one of the most annoying things for iOS users when iOS 6 came out is that their downloaded apps are not working with the new iOS version. Most of the apps in the AppStore (or any other download sites) were written to run in an optimal level with iOS 5, and maybe also with iOS 4. Software developers are not clairvoyant you know (... well maybe some but not all). So, if the app they created for iOS 5 is no longer functional in iOS 6, it is not completely--they are still liable for some errors because of their carelessness, of course--their fault. They won't know the changes to the SDK until, well, it's too late... (I just had my app publiiiiiiiiiiiiiiiiiiieeeeeeeshedaaaaargggh!!! - one random unhappy iOS developer)<br />
<br />
Anyway, so why are some apps not working or why are they crashing a lot? The answer, my friends, are the deprecated methods/functions (whatever you call them). Here are some of the common problems and the possible solutions to them:<br />
<br />
<b><i><br /></i></b>
<b><i>Problem 1:</i></b><br />
<br />
My app crashes every 5 minutes!<br />
<br />
<b><i>Causes:</i></b><br />
<b><br /></b>
<b>viewDidUnload</b><br />
<div class="p2">
Called when the controller’s view is released from memory. (<span class="s1" style="color: #e06666;">Deprecated in iOS 6.0.</span> Views are no longer purged under low-memory conditions and so this method is never called.)</div>
<div class="p2">
<br /></div>
<div class="p2">
</div>
<div class="p1">
<b>viewWillUnload</b></div>
<div class="p2">
Called just before releasing the controller’s view from memory. (<span class="s1" style="color: #e06666;">Deprecated in iOS 6.0.</span> Views are no longer purged under low-memory conditions and so this method is never called.)</div>
<div class="p2">
<br /></div>
<div class="p2">
<b><i>Solution:</i></b></div>
<div class="p2">
</div>
<div class="p1">
<b><br /></b></div>
<div class="p1">
Use <b>applicationDidReceiveMemoryWarning:</b> to handle low-memory conditions.</div>
<div class="p1">
<br /></div>
<div class="p1">
<b>applicationDidReceiveMemoryWarning:</b></div>
<div class="p2">
Tells the delegate when the application receives a memory warning from the system.</div>
<br />
<b><i><br /></i></b>
<b><i>Problem 2:</i></b><br />
<b><i><br /></i></b>
My app is not changing its orientation when I rotate the device!<br />
<br />
<b><i>Cause:</i></b><br />
<br />
<b>shouldAutorotateToInterfaceOrientation:</b><br />
<div class="p2">
Returns a Boolean value indicating whether the view controller supports the specified orientation. (<span class="s1" style="color: #e06666;">Deprecated in iOS 6.0.</span> Override the <span class="s2">supportedInterfaceOrientations</span> and <span class="s2">preferredInterfaceOrientationForPresentation</span> methods instead.)</div>
<div class="p2">
<br /></div>
<div class="p2">
<b><i>Solutions:</i></b></div>
<div class="p2">
<br /></div>
<div class="p2">
Use <b>shouldAutorotate</b>, <b>supportedInterfaceOrientations</b>, <b>preferredInterfaceOrientationForPresentation</b>.</div>
<div class="p2">
<br /></div>
<div class="p2">
</div>
<div class="p1">
<b>shouldAutorotate</b></div>
<div class="p2">
Returns whether the view controller’s contents should auto rotate.<br />
<b><br /></b>
<b>supportedInterfaceOrientations</b></div>
<div class="p2">
<div class="p2">
Returns all of the interface orientations that the view controller supports.</div>
<div class="p2">
<br /></div>
<div class="p2">
</div>
<div class="p1">
<b>preferredInterfaceOrientationForPresentation</b></div>
<div class="p2">
Returns the interface orientation to use when presenting the view controller.</div>
<div class="p2">
<br /></div>
<div class="p2">
<b><i><br /></i></b>
<b><i>Problem 3:</i></b></div>
<div class="p2">
<b><i><br /></i></b></div>
<div class="p2">
My app launched but is not showing anything!</div>
<div class="p2">
<br /></div>
<div class="p2">
<b><i>Causes:</i></b><br />
<b><br /></b>
<b>modalViewController</b></div>
<div class="p2">
<div class="p2">
The controller for the active presented view—that is, the view that is temporarily displayed on top of the view managed by the receiver. (read-only) (<span class="s1" style="color: #e06666;">Deprecated in iOS 6.0.</span> Use <span class="s2">presentedViewController</span> instead.)</div>
<div class="p2">
<br /></div>
</div>
<div class="p2">
</div>
<div class="p1">
<b>presentModalViewController:animated:</b></div>
<div class="p2">
Presents a modal view managed by the given view controller to the user. (<span class="s1" style="color: #e06666;">Deprecated in iOS 6.0.</span> Use <span class="s2">presentViewController:animated:completion:</span> instead.)</div>
<br />
<div class="p1">
<b>dismissModalViewControllerAnimated:</b></div>
<div class="p2">
Dismisses the view controller that was presented by the receiver. (<span class="s1" style="color: #e06666;">Deprecated in iOS 6.0.</span> Use <span class="s2">dismissViewControllerAnimated:completion:</span> instead.)<br />
<br />
<b><i>Solutions:</i></b><br />
<br />
Use <b>presentedViewController</b>, <b>presentViewController:animated:completion:</b>, and <b>dismissViewControllerAnimated:completion:</b>.<br />
<b><br /></b>
<b>presentedViewController</b><br />
<div class="p2">
The view controller that is presented by this view controller, or one of its ancestors in the view controller hierarchy. (read-only)</div>
<div class="p2">
<br /></div>
<b>presentViewController:animated:completion:</b><br />
<div class="p2">
Presents a view controller.</div>
<div class="p2">
<br /></div>
<div class="p2">
</div>
<div class="p1">
<b>dismissViewControllerAnimated:completion:</b></div>
<div class="p2">
Dismisses the view controller that was presented by the receiver.</div>
<br />
<br />
<br /></div>
</div>
Noyhttp://www.blogger.com/profile/02645704038220895675noreply@blogger.com1tag:blogger.com,1999:blog-7949621305572890118.post-57443776171896886042012-09-22T00:32:00.000+08:002012-09-22T00:35:09.203+08:00[iOS] Saving the Singleton Object's State to FileHere's a way to save a singleton object's state into a file.
<br>
TestSingleton.h:
<pre class="brush:c">
@interface TestSingleton : NSObject
@property (nonatomic, retain) NSString *testString;
+ (id)sharedInstance;
- (BOOL)saveState;
@end
</pre>
<br>
TestSingleton.m:
<pre class="brush:c">
#import "TestSingleton.h"
static TestSingleton *sharedInstance = nil;
@interface TestSingleton()
@property (nonatomic, retain) NSString *file;
@end
@implementation TestSingleton
@synthesize testString = _testString;
@synthesize file = _file;
- (void)dealloc
{
[_testString release];
[_file release];
[super dealloc];
}
+ (id)sharedInstance
{
@synchronized(self){
if(sharedInstance == nil){
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *testFile = [documentsDirectory stringByAppendingPathComponent:@"testfile.sav"];
Boolean fileExists = [[NSFileManager defaultManager] fileExistsAtPath:testFile];
if(fileExists) {
sharedInstance = [NSKeyedUnarchiver unarchiveObjectWithFile:testFile];
}
else{
sharedInstance = [[super allocWithZone:NULL] init];
}
sharedInstance.file = testFile;
}
}
return sharedInstance;
}
- (BOOL)saveState
{
return [NSKeyedArchiver archiveRootObject:self toFile:sharedInstance.file];
}
- (void)encodeWithCoder:(NSCoder *)aCoder{
[aCoder encodeObject:_testString forKey:@"test"];
}
- (id)initWithCoder:(NSCoder *)aDecoder{
self = [super init];
if(self){
_testString = [[NSString alloc] initWithString:[aDecoder decodeObjectForKey:@"test"]];
}
return self;
}
@end
</pre>
<br>
Now, in the app delegate:
<pre class="brush:c">
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
TestSingleton *singleton = [TestSingleton sharedInstance];
NSLog(@"PREVIOUS STATE: %@", singleton.testString);
//Update testString
singleton.testString = [[NSDate date] description];
NSLog(@"NEW STATE: %@", singleton.testString);
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
//This will save the state of the singleton object when the object tries to go the background
[[TestSingleton sharedInstance] saveState];
}
</pre>Noyhttp://www.blogger.com/profile/02645704038220895675noreply@blogger.com0tag:blogger.com,1999:blog-7949621305572890118.post-17927261355754617212012-09-14T11:38:00.000+08:002012-09-14T11:41:17.435+08:00String Representation of Date from UIDatePickerIn iOS, there's this UI element that allows the user to select the date and time. This is called the Date Picker.<br />
<br />
Here's a way of getting the text from the iOS' Date Picker:<br />
<br />
<br />
<span style="color: lime; font-family: Courier New, Courier, monospace;">/*_datePicker is the current UIDatePicker object. </span><span style="color: lime; font-family: 'Courier New', Courier, monospace;">Set the mode of the date picker. </span><span style="color: lime; font-family: 'Courier New', Courier, monospace;">In this example, setting the time is disabled.*/</span><br />
<span style="font-family: Courier New, Courier, monospace;">[<span style="color: #6fa8dc;">_datePicker</span> <span style="color: magenta;">setDatePickerMode</span>:<span style="color: magenta;">UIDatePickerModeDate</span>];</span><br />
<span style="color: lime; font-family: Courier New, Courier, monospace;">/*Initialize a NSDateFormatter object. </span><span style="color: lime; font-family: 'Courier New', Courier, monospace;">This object will get the string representation of the NSDate object.*/</span><br />
<span style="font-family: Courier New, Courier, monospace;"><span style="color: #6fa8dc;">_dateFormatter</span> = [[<span style="color: magenta;">NSDateFormatter alloc</span>] <span style="color: magenta;">init</span>];</span><br />
<span style="color: lime; font-family: Courier New, Courier, monospace;">/*Set the locale of the NSDateFormatter object.*/</span><br />
<span style="font-family: Courier New, Courier, monospace;"><span style="color: magenta;">NSLocale </span><span style="color: #6fa8dc;">*locale</span> = [[[<span style="color: magenta;">NSLocale alloc</span>] <span style="color: magenta;">initWithLocaleIdentifier</span>:<span style="color: red;">@"en_EN"</span>] <span style="color: magenta;">autorelease</span>];</span><br />
<span style="font-family: Courier New, Courier, monospace;">[<span style="color: #6fa8dc;">_dateFormatter</span> <span style="color: magenta;">setLocale</span>:<span style="color: #6fa8dc;">locale</span>];</span><br />
<span style="color: lime; font-family: Courier New, Courier, monospace;">/*Set the date style and the time style of the formatter. </span><span style="color: lime; font-family: 'Courier New', Courier, monospace;">Note that the next two lines of code are important. </span><span style="color: lime; font-family: 'Courier New', Courier, monospace;">Without them, when NSDateFormatter's instance function/method - stringFromDate: </span><span style="color: lime; font-family: 'Courier New', Courier, monospace;">is used, the returned string is empty. </span><span style="color: lime; font-family: 'Courier New', Courier, monospace;">It is not stated in the NSDateFormatter class reference that the default value of </span><span style="color: lime; font-family: 'Courier New', Courier, monospace;">dateStyle and timeStyle are set to NSDateFormatterNoStyle but I </span><span style="color: lime;"><span style="font-family: Courier New, Courier, monospace;">think they are.*/</span></span><br />
<span style="font-family: Courier New, Courier, monospace;">[<span style="color: #6fa8dc;">_dateFormatter</span> <span style="color: magenta;">setDateStyle</span>:<span style="color: magenta;">NSDateFormatterLongStyle</span>];</span><br />
<span style="font-family: Courier New, Courier, monospace;">[<span style="color: #6fa8dc;">_dateFormatter</span> <span style="color: magenta;">setTimeStyle</span>:<span style="color: magenta;">NSDateFormatterNoStyle</span>];</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">...</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="color: lime; font-family: Courier New, Courier, monospace;">/*This is the code for getting the string representation of the selected date*/</span><br />
<span style="font-family: Courier New, Courier, monospace;"><span style="color: magenta;">NSString </span>*<span style="color: #6fa8dc;">selectedDate</span> = [<span style="color: #6fa8dc;">_dateFormatter</span> <span style="color: magenta;">stringFromDate</span>:<span style="color: #6fa8dc;">_datePicker</span>.<span style="color: magenta;">date</span>];</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<br />
Note: Automatic Reference Counting (ARC) is not used in this example.Noyhttp://www.blogger.com/profile/02645704038220895675noreply@blogger.com0tag:blogger.com,1999:blog-7949621305572890118.post-56181470386590140402012-02-13T14:36:00.000+08:002012-09-14T11:39:07.015+08:00How To Make GDataXMLNode Work<span style="font-size: 100%;">To use GDAtaXMLNode, both the .h and .m files must be added to your code. Then do the following:</span><br />
<div>
<ol>
<li>Select the project.</li>
<li>Select <b>Build Phases</b> tab.</li>
<li>Expand <b>Link Binary With Libraries</b>. Click <b>+</b>.</li>
<li>Locate <b>libxml2.dylib</b> then click <b>Add</b>.</li>
<li>Select Build Settings tab.</li>
<li>Under <b>Search Paths</b> > <b>Header Search Paths</b>, Select <b>Debug</b> then click on the little white circle with the blue plus sign inside.</li>
<li>On the value field, enter <b>"/usr/include/libxml2"</b> without the quotation mark.</li>
<li>Click the icon with two little black triangles, which is on the left of the little white circle with blue minus sign inside, then select <b>Any architecture</b>.</li>
<li>Repeat step 8, select <b>Any SDK</b>.</li>
<li>Under <b>Search Paths</b> > <b>Header Search Paths</b>, Select <b>Release </b>then click on the little white circle with the blue plus sign inside. </li>
<li>Repeat steps 7 to 9 for Release.</li>
</ol>
<div>
If your code is using Automatic Reference Counting (ARC) do the following:</div>
</div>
<div>
<ol>
<li>Select <b>Build Phases</b> tab. </li>
<li>Expand <b>Compile Sources</b>.</li>
<li>Select <b>GDataXMLNode.m</b> then press Enter.</li>
<li>On the small input box that pops-out, enter <b>-fno-objc-arc</b>.</li>
</ol>
<div>
And you are done! :)</div>
</div>
Noyhttp://www.blogger.com/profile/02645704038220895675noreply@blogger.com0tag:blogger.com,1999:blog-7949621305572890118.post-43962759610171171952012-01-31T14:35:00.000+08:002012-09-21T14:33:29.959+08:00Objective-C: Creating a Random Number and Storing To NSStringI wanted to generate a random number and convert it to NSString:<br />
<div>
<br /></div>
<div>
<pre class="brush:c">
NSString *myRandomNumber = [NSString stringWithFormat: @"%u", arc4random()];
</pre></div>Noyhttp://www.blogger.com/profile/02645704038220895675noreply@blogger.com0tag:blogger.com,1999:blog-7949621305572890118.post-67608850469373205092012-01-18T14:30:00.000+08:002012-01-31T14:52:05.152+08:00How to SVN Checkout through Mac Terminal<div style="text-align: justify;">I am currently learning iOS development and one of the things I need to do is checkout the current code for our iOS project. As of the moment, after clean installing the OS of my workstation which is a MacBook Pro, I haven't installed any application yet other than Xcode. So to checkout the code, I used the Terminal. The checkout is very simple:</div><br /><ol><li>Open Terminal through Launchpad > Utilities</li><li>On Terminal, type svn co https://your.svn.url --username your_username --password your_password</li></ol><br />Note: --username is optional. --password is conditional: username must be present.Noyhttp://www.blogger.com/profile/02645704038220895675noreply@blogger.com2tag:blogger.com,1999:blog-7949621305572890118.post-22798716751549528842011-11-10T07:50:00.000+08:002011-11-09T15:51:58.137+08:00J2ME at the Brink of ExtinctionI realized that the growing number of smart phones on the market is heavily tearing down the marketability of JME (or J2ME) apps. JME has been around for about a decade and might be nearing its end with the rise of platforms like the Android, iOS, and Windows mobile.<br /><br />Since in my line of work I have to deal with JME applications, I see that there are those who prefer JME apps over Android or iOS apps. One reason is that not everyone (or every country) is up to date with the latest mobile technologies, most especially with mobile phones. For example, a phone that was phased out by Nokia six years ago is possibly the widely used or sold phone by a telecom company in a third world country.<div><br /></div><div>Oracle announced that they will modernize JME. But until the product is made available to the public, JME is a dying technology.<br /><br />Although this (JME use is declining) is the trend that I see, perhaps I will still use JME for a long time. Or maybe a year or two. Right now I find JME apps development very exciting. There are tons of technologies related to JME that I haven't explored yet. Maybe by the time I fully set aside JME development there are still plenty to be learned. Right now I am just thankful to be able to work on JME apps. However, learning new skills on Android or iOS development would pretty much add more to my understanding on mobile technologies.<br /></div>Noyhttp://www.blogger.com/profile/02645704038220895675noreply@blogger.com0tag:blogger.com,1999:blog-7949621305572890118.post-77230089146760483682010-05-21T13:51:00.001+08:002012-03-13T11:17:10.169+08:00Debug Your JME App<a href="http://findbugs.sourceforge.net/">Findbugs™</a> is one really super cool tool for Java developers. It does excellent in locating errors in the source code especially those that are not obvious to the programmer's eye. One interesting thing is that it can also analyze Java applications for MIDP devices.<br /><br />Here's a simple how-to-use for you if you want to analyze your JME project.<br /><br />1. Download the <a href="http://prdownloads.sourceforge.net/findbugs/findbugs-1.3.9.zip?download">Findbugs™ application</a>.<br />2. Extract the contents of the zip file to any directory.<br />3. Go to bin folder and execute findbugs.bat.<br />4. To start a new analysis select <span style="font-style: italic;">File > New Project</span>.<br />5. Write a name on the <span style="font-style: italic;">Project name</span> field.<br />6. (I suppose you already have the jar file of your project at this point.) On <span style="font-style: italic;">Class archives and directories to analyze</span>, click <span style="font-style: italic;">Add</span> and then select the jar file to be analyzed. Make sure that the target jar was built without any obfuscation.<br />7. For <span style="font-style: italic;">Auxillary class locations</span>, select <span style="font-style: italic;">Add</span> then locate the JSR jar files that were used/imported in your JME project. By default, these JSR files are bundled with NetBeans so if you are using NetBeans IDE look for them in the NetBeans intallation directory (they are located in the [NetBeans 6.8] mobility8 folder... and I'm not yet sure about Eclipse... I haven't used Eclipse for a while). If you are not sure which to add, select all of the jar files.<br />8. For <span style="font-style: italic;">Source directories</span> just select the source code folder. Example, C:\Myporject\src<br />9. Finally, click <span style="font-style: italic;">Finish</span>. Analysis will start immediately.<br /><br />Note that not every bug that are detected in the analysis is valid. You have the option to tag its validity. Yet this tool is very effective in detecting a number of errors in your code that you failed to notice maybe because of the structure of the code, or its complexity, or maybe because of your style of coding.Noyhttp://www.blogger.com/profile/02645704038220895675noreply@blogger.com0