Loading every different user own data - iphone

I am making an app that the user could add many accounts and view it in the UITableView and I am holding the name via NSUserDefaults and once the name is clicked in the UITableView it will open a different page that has many data fields to fill which is DONE.
For example when the user click on John or other name. The user could see his own data. My problem is that how could I show for every user his own data? Also could I make this via NSUserDefaults ?
It smiler to contacts tab in the iPhone. I hope I could explain my problem.
My source code I hope it helps Download Link

This answer hasn't common answer without knowing your architecture and data which you show in table. Generally database greatly solve this problem - you store all data in db and fetch by predicate only needed data -
NSPredicate *predicate = [NSPredicate predicateWithFormat:#"name== %#", userName];
NSArray *orders = [Order findAllUsingPredicate:predicate]; // this is prototype method
But database is being used for large amount of data, and if you don't want to use db or have static data to display then look at plists. You can create plist with nodes
-John
-Order1,Order2
-Mike
-Order3,Order4,Order5
...
Then read this file, and fetch John's object like this:
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:pathToPlist];
johnsObjects = [dict objectForKey:#"John"];
Hope, it will be helpful for you

Use a document-based app (UIDocument). Give each user his own document. Switch between documents when you switch users. See Document-Based App Programming Guide for iOS.

Related

iPhone Dev - Creating a one time UIAlertView like in Temple Run

You know how Temple Run sometimes has alerts when you open the App that appear even though you don't update the App? I understand how you would implement this if you were to submit an update to your App, but how does Imangi implement new alerts without releasing new versions of the App? (I'm assuming they upload it from some server, but I'm an amateur at all of that stuff so could someone sorta vaguely explain how I might go about doing that? Will I need to learn Internet programming languages :O?)
Thanks.
I agree with Jonathan. I would set a plist with a reference number on your server. and it would look something like this. I'm using concept, not code. It would be as simple as hosting it on your server. Or it could be as complicated as your creating a user interface on your website that allows you to just plug in the information and it would create the plist for you.
-(void)checkanddisplaynotificationbasedonupdatedplistontheserver{
int currentnotificationnumber = userprefs preference for item "notification"
get and parse notification.plist from your server
notificationnumber = object at index 0
if notificationnumber > currentnotificationnumber{
display your notification with parsed plist
}
}
You could host a plist online, with an array of alerts stored as dictionaries, with attributes like 'title', 'body' etc. The app would then parse this and to create an alert. You could then set up a method which searches for updates to this file every time the app opens and has connectivity.
This is not the only way - there are probably hundreds of other files types/ automated systems to use, however this is a simple way, and roughly how all of them work, and I have implemented something like this in some of my apps. Hope this helps, if you wan't any help coding it, I will be happy to help!
Jonathan

How to retrieve all contacts from ABAddressBook without duplicates

To get all contacts I'm using ABAddressBookCopyArrayOfAllPeople method but, this method return all contacts with duplicates: in "Contacts" app I saw that almost every my contacts has linked card (it's show me that I have two same contacts one from iCloud and an other from my iPad). As I see in this reason ABAddressBookCopyArrayOfAllPeople method return duplicate contacts.
How to get all contacts from ABAddressBook without duplicate?
Maybe the ABContactHelper could help?!
From memory I think this returns only one record per user:
ABRecordRef source = ABAddressBookCopyDefaultSource(addressBook);
addressBookArray = (__bridge_transfer NSArray *)ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(addressBook, source, kABPersonSortByLastName);
I've used it an it appears to work. Although you will have to jump through the linked contacts to get all the details about a user.
Remember to CFRelease source and addressBook when you are finished.
I had the same problem and did not find another solution then the manual bidirectional-link-duplicate-removal process:
Two cascaded cycles (ordo n^2) that confronts the record ID of each contact-pair that was returned by ABAddressBookCopyArrayOfAllPeople. Then I add to the final list only the contact with the smaller contact ID. It's not very beautiful solution but it works for me.

How to add notes functionality in myApp in iphone?

I want to add notes functionality in myApp in iphone so that whenever i would open that notes in future,I would get that along with the date and time of writing that note.
Edit-1:
I want to make notes in my application. I also want to add edit functionality in that notes so that whenever i will open that in future I would be able to edit that and store that for the future with time and date of editing that notes.So i want to make list of the notes which i would make for myself in my application.Please help me regarding this.Thanks in advance and ask whatever u want to give the answer of this question.
What you're trying to do seems very simple. There are SEVERAL ways to go about doing something like that. A couple options off the top of my head:
Create a "Note" object with properties like:
NSString note;
NSDate lastEdited;
And just store it in a file. So whenever the user modifies your data just go:
lastEdited = [NSDate date]; To set the date to the current time.
Personally the way I would handle this is to persist(store) the data in Core Data. That way instead of having to write your data to file each time it's modified you can save the data in one line of code:
[myNote.managedObjectContext save:&error].
I hope this helps. If not there's a similar question that has already been answered here:
Save object in CoreData

How to use NSUbiquitousKeyValueStore and NSUserDefaults together

Documentation is not clear on how to use NSUbiquitousKeyValueStore with edge cases.
If I want to set a value, I understand that I should set a value to both NSUserDefaults and NSUbiquitousKeyValueStore since iCloud could be disabled. However in my tests [NSUbiquitousKeyValueStore defaultStore] return a valid object even if iCloud is disabled (tested on Mac OS).
Also, to my understanding is that if iCloud is enabled, NSUbiquitousKeyValueStore's values are stored to disk (and available offline). What are the reason to use NSUserDefaults if you are sure that you have less than 64KB of data?
I am using
http://blog.mugunthkumar.com/coding/ios-code-mkicloudsync-sync-your-nsuserdefaults-to-icloud-with-a-single-line-of-code/
It is a simple class written by Mugunth Kumar (thanx !) that does the work for you... Unless you have special needs, add one line of code and it will do all the reading and writing to iCloud... all you need to do is read and write to NSUserDefaults as usual...
Edit:
Carful, if you remove an item from NSUserDefaults the code I linked to above will not remove the item from the cloud. Whenever you remove an item from NSUSerDefaults please do the same to NSUbiquitousKeyValueStore as So:
NSUbiquitousKeyValueStore* keyValueStore=[NSUbiquitousKeyValueStore defaultStore];
[keyValueStore removeObjectForKey: yourKey];
The Mugunth Kumar answer provided above works beautifully if you want to sync all of your NSUserDefaults!
However, it is an ALL or NOTHING approach. You can not pick or choose the defaults you wish to sync.
I found this Tutorial that may be of assistance if you are looking to be more picky.
I wrote a simple iOS category that can be used to save a value also into NSUbiquitousKeyValueStore while storing into NSUserDefalt.
hope this help:
https://github.com/RiccardoPaolillo/NSUserDefault-iCloud

Create an empty ABAddressBook in iPhone SDK?

Can I create an ABAddressBook which does not read data from my address book. i.e. it's empty to start with so that I can put in my own contacts fetched from the internet.
As you may know the function
ABAddressBookRef ab = ABAddressBookCreate();
gives me data from the built in addressbook. This is not what I want but if you know a solution to my problem please let me know.
I don't think it is possible to have an empty instance of ABAddressBook. The documentation is only about getting an ABAddressBook filled with the address book of the iPhone.
You could try making an array (or mutablearray) that you fill with the contacts and put the array inside a UITableView.
I've been working on a "private contacts" app which stores contacts off of the normal address book and I can confirm that this is indeed possible, if only through a little manipulation. Using the ABAddressBookRef variable, however, won't help you at all. What you need is a NSMutableArray of ABRecordRef's, which is how iOS stores its contacts.
You could try to zero out ABAddressBookRef with a memset/calloc and see if that gives you the desired result.