Passing Data with TTNavigator
Three20 has a nice way of handling navigation between controllers. One thing that is not immediately obvious is passing data to the controller. From the sample code and the extremely short wiki page, we can see how to pass data with a query parameter when there is another parameter.
NSArray*arr =[...load up with data...];
[[TTNavigator navigator] openURLAction:[[TTURLAction actionWithURLPath:@"tt://restaurant/Chotchkie's"]
applyQuery:[NSDictionary dictionaryWithObject:arr forKey:@"arrayData"]]];
-(id) initWithName:(NSString*)name query:(NSDictionary*)query
{
for(MyObject* item in[query objectForKey:@"arrayData"])
//... do something with item ...
}
// ...
}
But, what happens when you only want to pass the query parameter?
- (id)initWithNavigatorURL:(NSURL*)URL query:(NSDictionary*)query
Obvious right!
Thanks StackOverflow
iOS and Custom Fonts
Recently, I was working on a game with Cocos2d and keep getting this weird iOS version problem. On iOS 5, all my labels were shown as expected but on iOS 4 labels somehow kept disappearing. First I thought this is because of the retina display and point/pixels stuff. However, it was because of the fonts I was using. HelveticaNeue-CondensedBold and HelveticaNeue-CondensedBlack are available on iOS 5, but not on iOS 4 (http://iosfonts.com/).
I googled to see how easy to add custom fonts and it turned out, it is super easy.
These are the links I found helpful:
Animating Views with iPhone Keyboard
Keyboards on iPhone can be a headache with their half screen size, especially when you have many input fields on a single view. Animating the view in an elegant way so that the input fields are always visible to the user requires to slide up or down with the keyboard synchronously.
Following is a very simple view based project, that will demonstrate animating view with keyboard slide up/down.
But first, let’s see the problem. If you don’t change your view positioning when the keyboard becomes visible, basically you are likely to get something like this:
To fix that, what should be done is to listen the keyboard slide up/down notifications through the NSNotificationCenter, which viewWillAppear is a good place to start listening these two notifications.
-(void)viewWillAppear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(slideUpView:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(slideDownView:) name:UIKeyboardWillHideNotification object:nil];
}
Second step is to change the positioning of the components according to the animation of the keyboard. The following methods are called when there is a notification from the keyboard:
-(void)slideDownView:(NSNotification*)notification
{
[[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&animationCurve];
[[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&animationDuration];
[[[notification userInfo] objectForKey:UIKeyboardBoundsUserInfoKey] getValue:&keyboardFrame];
[UIView animateWithDuration:animationDuration
delay:0.0
options:animationCurve
animations:^{
self.view.frame = CGRectMake(0, 0, 320, 480);
}
completion:^(BOOL finished){
NSLog(@"Slide down Done..!");
}];
}
-(void)slideUpView:(NSNotification*)notification
{
[[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&animationCurve];
[[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&animationDuration];
[[[notification userInfo] objectForKey:UIKeyboardBoundsUserInfoKey] getValue:&keyboardFrame];
//
[UIView animateWithDuration:animationDuration
delay:0.0
options:animationCurve
animations:^{
self.view.frame = CGRectMake(0, -keyboardFrame.size.height + 70, 320, 416);
}
completion:^(BOOL finished){
NSLog(@"Slide up Done..!");
}];
}
Don’t forget to add .h file the following declarations:
// in controller's .h file NSTimeInterval animationDuration; UIViewAnimationCurve animationCurve; CGRect keyboardFrame;
The final result is something like this
note 1: Feel free to download the source code (link). It also includes the slide down via the button.
note 2: The licence to this peace of code is Beerware, In short, “Should the user of the product meet the author and consider the software useful, he is encouraged to buy the author a beer ‘in return’ (or, in some variations, drink a beer in the author’s honor).”
There are lots of sources about how to start AWS EC2, but this abundance can be intimidating and confusing. During the last summer, when I tried to find a hosting solution for Remotespots, I briefly tried AWS EC2, but then switched to Eapps since they speed things up.
What you need to do in three steps is that
- Sign up to AWS, connect to AWS (preferable with Amazon EC2 API Tools)
- Create an instance (via API tools or the web console)
- Connect to that instance via SSH.
These are the steps that works for me,
1. Sign up AWS — http://aws.amazon.com/
2. Follow the steps at that link, and create X.509 certificate (also download private key when doing that)
3. Create an instance from the https://console.aws.amazon.com/ec2/ (Don’t forget to save the private key .pem file while creating the instance)
5. Follow the steps here http://paulstamatiou.com/how-to-getting-started-with-amazon-ec2 for connecting to the instance via SSH.
Links that helps
- AWS console – https://console.aws.amazon.com/ec2/
- AWS portal — https://aws-portal.amazon.com/
- Starting Amazon EC2 with Mac OS X — http://www.robertsosinski.com/2008/01/26/starting-amazon-ec2-with-mac-os-x/
- How To: Getting Started with Amazon EC2 — http://paulstamatiou.com/how-to-getting-started-with-amazon-ec2
- Connect to Your Linux/UNIX Instance — http://docs.amazonwebservices.com/AWSEC2/latest/GettingStartedGuide/
Say you let your user draw thing and let them go wild with their imaginations, as they probably create awesome drawings, you should probably want to save these images to somewhere.
After this short happy talk, here is the code snippet that saves your UIImage to the Documents folder with its alpha channel, if there is one. The other method is for reading that image back to an UIImage instance.
-(void)saveImageToDocs:(NSString *)fileName
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath2 = [NSString stringWithFormat:@"%@/%@.png", documentsDirectory, fileName];
// If you use this method, the transparency will be lost
//NSData* imageData = UIImageJPEGRepresentation(drawImage.image, 1.0);
//NSData* imageData = UIImagePNGRepresentation(drawImage.image);
//[imageData writeToFile:filePath2 atomically:NO];
// So use this one
[UIImagePNGRepresentation(myUIImage) writeToFile:filePath2 atomically:YES];
}
-(void)loadImageFromDocs:(NSString *)fileName
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath2 = [NSString stringWithFormat:@"%@/%@.png", documentsDirectory, fileName];
if([[NSFileManager defaultManager] fileExistsAtPath:filePath2])
{
NSLog(@"image file exists");
myUIImage = [UIImage imageWithContentsOfFile: filePath2];
}
}
E-ticaret Kitabindan Notlar
Normalde e-ticaret’te soyle yapmali, basariya giden yol icin oneriler vs kitaplari pek samimi olmuyor gibi, bu kitaba da uykumu getirmesi icin soyle bir bakayim diye elime aldim, ama icinde etohum projeleri ile ilgili yazilar gorunce okumaya karar verdim.
Digital Age dergisnin Kasim 2010 sayisi ile verilen “e-ticaret Satista Tsunami Etkisi — Anil Altas” kitabi (Sina Afra’nin onsozunu yazmis) hafif uzun bir blog yazisi gibi okunabiliyor. Iki saat gibi bir surede bitirebilirsiniz.
Kitabi okurken aldigim notlar ve ilgimi ceken maddeler asagidaki gibi:
- Sina Afra — (http://www.pctime.com.tr/habergoster.asp?id=1815)
- Alice Harikalar Diyarinda’dan cok guzel bir alinti
“Would you tell me, please, which way I ought to go from here?”
“That depends a good deal on where you want to get to,” said the Cat.
“I don’t much care where–” said Alice.
“Then it doesn’t matter which way you go,” said the Cat.
“–so long as I get SOMEWHERE,” Alice added as an explanation.
“Oh, you’re sure to do that,” said the Cat, “if you only walk long enough.”
(Alice’s Adventures in Wonderland, Chapter 6)
(http://www.alice-in-wonderland.net/books/alice-in-wonderland-quotes.html)
- Like.com kurucusu Burak Gokturk (http://www.webrazzi.com/2010/01/18/roportaj-like-com-kurucusu-burak-gokturk/)
- 3D Secure (http://en.wikipedia.org/wiki/3-D_Secure)
- Turkiye’den ihrac ile ilgili bir not: 1.500 Euro ve 30 kilo alti urunler internet ustunden satilabilmekte
- Kadinlar e-ticarette kararlarin %80′inin sahibi imis (nrf.com)
- 2013′de mobil cihazlarin internete ana erisim yolu olacakmis (Morgan Stanley)
- Ebay ve Amazon ikisi de 1994′de kurulmus
Below you can find the summary of available alternatives for storing data on iOS based machines. Mainly, which one to use depends on your needs like size of data, need of concurrency, access speed, etc.
- NSUserDefaults
- Based on plists
- Store lightweight app state
- Tutorial (link)
- Plist — Writing everything out as a plist
- Archived Objects
- Conteptual guide (link)
- Archives provide a means to convert objects and values into an architecture-independent stream of bytes that preserves the identity of and the relationships between the objects and values.
- Serialization converts Objective-C types to and from an architecture-independent byte stream. In contrast to archiving, basic serialization does not record the data type of the values nor the relationships between them; only the values themselves are recorded. Arbitrary objects cannot be serialized. Only instances of NSArray, NSDictionary, NSString, NSDate, NSNumber, and NSData (and some of their subclasses) can be serialized. (link)
- Forum post about how to use archiver (link)
- The joy of SQLite
- Basically a local file act like a database server
- Not very good for extreme concurrent access
- A step by step tutorial (link)
- Core Data
- Higher abstraction layer than SQLite
- Save&load model objects
- ORM (Rails ActiveRecord, Java Hibernate)
- Use NSPredicate for in memory filtering
- Apple Dev Center Article (link)
- Web Services
- Store & access remote data
- XML and Json parsers
ps. Related Stackoverflow entry
Amazon S3 and Paperclip on Rails 3
I previously posted about Using Amazon S3 with Paperclip. This post will talk about same topic. But this time for Rails 3.
gem 'aws-s3'
and run
bundle install
development: bucket: bucket-dev access_key_id: xxx secret_access_key: xxx test: bucket: bucket-test access_key_id: xxx secret_access_key: xxx production: bucket: bucket-pro access_key_id: xxx secret_access_key: xxx
#paperclip
has_attached_file :photo,
:styles => {
:thumb=> "100x100#",
:small => "400x400>" },
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => "/:style/:id/:filename"
That’s it! Simple isn’t it.
links that might help
Creating indexes on Google App Engine / Java (gae/j) is an easy job. You don’t even have to think about it (well, for some time)
For etohum admin application we used gae/j and it has been almost two years and gae/j has been improved a lot, but still, it has some really annoying features (bugs — I am not sure how to named them).
This time, it is the Datastore Indexes. Some of the pages requires indexes like
![]()
which turns out to be confusing for the auto generation tool. If, let’s say, you change the order of the last two fields,
like this
![]()
you will not get it automatically.
Even if you explicitly define it in your datastore-indexes.xml file
<datastore-index kind="Application" ancestor="false" source="manual"> <property name="applciationIsFinished" direction="asc"/> <property name="isSpam" direction="asc"/> <property name="sezonId" direction="asc"/> <property name="bitisTarihi" direction="desc"/> <property name="basvuruTarihi" direction="desc"/> </datastore-index>
And the workaround for the problem is stated in the last paragraph of Using Automatic Index Configuration documentation
It’s a good idea to occasionally move index configuration from
datastore-indexes-auto.xmltodatastore-indexes.xml, then disable automatic index configuration and test your app in the development server. This makes it easy to maintain indexes without having to manage two files, and ensures that your testing will reproduce errors caused by missing index configuration.
So change the datastore-indexes.xml file and add manually the all required indexes and upload the application.
<datastore-indexes autoGenerate="false">
You can change it back to auto generate after make sure the desired indexes are created.
ps. A tip about gae/j is that it is considerable faster when it is 4AM-7AM at the west coast of North America.













