iOS Autocomplete UITEXTVIEW | Add autocomplete suggestions dynamically - ios

I've been trying to implement an autocomplete UITEXTVIEW for my email app using this
https://github.com/hoteltonight/HTAutocompleteTextField
I would like to add the email addresses dynamically though. Is there any way to achieve the same. Because when I checked, the email addresses are initialised at start as given below.
HTEmailAutocompleteTextField.m
- (void)setupAutocompleteTextField
{
[super setupAutocompleteTextField];
// Default email domains to suggest
self.emailDomains = #[ #"gmail.com", #"yahoo.com"];
self.autocompleteDataSource = self;
}
The above method is called from HTAutocompleteTextField.m[- (void)awakeFromNib] as soon as the app is launched thereby not letting me to add email addresses dynamically.
Is there any work around because I get my email addresses later.
Any help is much appreciated.

Have you tried this from GitHub readme
HTAutocompleteTextField *textField = [[HTAutocompleteTextField alloc] initWithFrame:CGRectMake(0,0,100,31)];
The data source is the brains of the autocomplete logic. If you just want to autocomplete email addresses, use HTAutocompleteManager from the example project as follows:
textField.autocompleteDataSource = [HTAutocompleteManager sharedManager];
textField.autocompleteType = HTAutocompleteTypeEmail;
Alternatively, you may wish to create your own data source class and user the autocompleteType property to differentiate between fields with different data types. A HTAutocompleteTextFields's data source must implement the following method, as part of the HTAutocompleteDataSource protocol.
-(NSString *)textField:(HTAutocompleteTextField *)textField completionForPrefix:(NSString *)prefix ignoreCase:(BOOL)ignoreCase

Related

CoreData not returning updated values

I'm working with some existing code that interacts with CoreData. I made some changes that I later realized introduced a regression. I was able to isolate the lines of code that introduced the problem, but I cannot for the life of me understand why it's an issue at all.
The code involves reading articles and marking them as read. I didn't make any changes to the marking code and determined that still functions correctly. However, in another layer of the code that's getting the list of read articles, I made the following change:
//Old
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
...
[self retrieveReadArticles];
...
}
- (void)retrieveReadArticles {
userHistory = [UserHistory retrieveUserHistory]; //stored in iVar
self.readArticles = userHistory.readArticles;
}
The above works fine, and gives me an updated list of read articles.
//New
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
...
[self retrieveReadArticles];
...
}
- (void)retrieveReadArticles {
UserHistory* userHistory = [UserHistory retrieveUserHistory]; //local variable
self.readArticles = userHistory.readArticles;
}
This change in scope breaks the functionality, and causes the list of read articles to never update.
A colleague and I were speculating that the ivar allows the operation to complete fully, while the local variable must not be retained properly and goes out of scope before it can return updates. Can anyone point me toward a resource that explains this unexpected behavior?
It looks like the marking code may have been the problem after all. We were retrieving a dictionary of existing read articles, adding another entry to it, and saving the UserHistory object again. Changing that code to create a brand new dictionary with the existing read articles appears to solve the problem without needing to use ivar scope.

How to make Location auto complete text box Swift ios 8

I am trying to make a simple app which allows the user to get the longitude and latitude corresponding to a specific address. I want to provide the user with a search box similar to the one in google maps. Specifically I would like some sort of autocompletion to ensure the user enters a valid address. Is it possible to create an instance of google maps search box?
SPGooglePlacesAutocomplete is a simple objective-c wrapper around the Google Places Autocomplete API.
Look at this API from github which might be helpful- https://github.com/spoletto/SPGooglePlacesAutocomplete
Usage shown as per link. Adding the .h file you can have access to the functions which implement the Google places API from within the function. You can set parameters like partial address string, radius, language your app uses, your location (lat,long)
#import "SPGooglePlacesAutocompleteQuery.h"
...
SPGooglePlacesAutocompleteQuery *query = [SPGooglePlacesAutocompleteQuery query];
query.input = #"185 berry str";
query.radius = 100.0;
query.language = #"en";
query.types = SPPlaceTypeGeocode; // Only return geocoding (address) results.
query.location = CLLocationCoordinate2DMake(37.76999, -122.44696)
Then, call -fetchPlaces to ping Google's API and fetch results. The resulting array will return objects of the SPGooglePlacesAutocompletePlace class.
[query fetchPlaces:^(NSArray *places, NSError *error) {
NSLog(#"Places returned %#", places);
}];
It also has a example project which can be used.

Google+ API in iOS, GPPShare recipient setting

I am trying to integrate GooglePlus inside an iOS app of mine.
The app sends a simple message. I have a few questions about the setting of the recipient(s).
Here is the kind of code I am using:
[GPPShare sharedInstance].delegate = self;
id<GPPNativeShareBuilder> shareBuilder = [[GPPShare sharedInstance] nativeShareDialog];
[shareBuilder setPrefillText:#"Hello world! How is everything?"];
[shareBuilder setPreselectedPeopleIDs:#"112233445566778899000"]; // Question point!!
if (![shareBuilder open]) {
NSLog(#"Status: Error (shareBuilder cannot open).");
}
When the line with the comment "Question point!!" is present, I can set one(or a few) individual(s) as recipient(s) of the message.
When it is not present the set of recipients defaults to "Friends".
Here are my two questions:
Is it possible to set one of my circles (or a community) as recipient? Not only "Friends".
When using the "setPreselectedPeopleIDs:" method, one needs the ID of the recipient. How do we find this ID? There are documents and videos on the net showing how to find one's own ID, but since people usually send messages to other peole rather than to themselves, it would also be useful to know how to get other's IDs.
Doesn't seem like you can share with a specific circle.
You can use this method to get all of the visible people in the user's circles using this method
queryForPeopleListWithUserId:collection:
which is outlined here:
https://developers.google.com/+/mobile/ios/people
Explanation of the parameters from the header:
// List all of the people in the specified collection.
// Required:
// userId: Get the collection of people for the person identified. Use "me" to
// indicate the authenticated user.
// collection: The collection of people to list.
// kGTLPlusCollectionVisible: The list of people who this user has added to
// one or more circles, limited to the circles visible to the requesting
// application.
And another question that goes into this a little bit:
How to Fetch Google Plus circles in IOS Sdk
It does not seem to me like you can discern who is in what circle, unfortunately.

iOS RestKit artificial identification attributes

linked RestKit issue #1604
If my API gives me no id attribute, but i still want to cache the objects via Core Data, what should i use to identify my object.
For example i have
response = {
translation = {
text = "longlongtext";
dictionary = "general";
lang = "en";
};
otherdata = {
author = "May";
date = "434134";
};
}
So i would be glad to use hashed (md5) translation text as an id string.
Notice that my future requests which happen without network connection should be able to identify this cached entity and give it as a result.
I cant declare mapping to fill responseID property from [translation.text md5hash] to use as responseMapping.identificationAttributes = #[ responseID ]; because mappings doesnt have such feature.
As proposed by #segiddins in the github issue discussion:
... in your managed object subclass, hook into one of the core data callbacks to generate a compound key that is saved as part of the model and just use that key as your identification attribute.
The approach may look like this:
#property (nonatomic, copy) NSString *identifier;
- (void)willSave
{
[super willSave];
NSString *computedIdentifier = [[NSString stringWithFormat:#"%#%#", self.text, self.langCode] md5hash];
[self setPrimitiveValue:computedIdentifier forKey:#"identifier"];
}
I also wanted to do a hash of the JSON fields like you, but as you know it's not possible. I ended up doing the following to achieve (I believe) the same end result, which is for JSON objects returned without a unique ID, a unique identification attribute is generated by RestKit:
entityMapping.identificationAttributes = #[ #"text",#"dictionary",#"lang",#"author",#"date" ];
You should keep this kind of functionality outside of RestKit if you have no identifiers being provided by the server.
I would generate a custom identifier for each request you make (a GUID), I'd save that identifier into each of the result objects in the RestKit success completion block. I'd also save the request details and the identifier into user defaults.
Now, when the user makes a request and they are offline you can analyse user defaults to determine if it's a repeat request and find the identifier with which to query the results from the data store.
Just to clarify about offline requests after discussion.
In the end, such feature (offline requests) does not exist inside RestKit. The way you can achieve it is complicated, but possible. Steps are:
you use CoreData with RestKit (RKEntityMapping, managed objects etc)
Your provide good identification attributes for entities. It can be URL of request from #metadata.
on both success and failure callbacks from getObjectsAtPath you query CoreData with fetch request and return the result just the same way as if it was loaded directly and taken from mappingResult.firstObject and mark it as cached if it is old result loaded on failure.

Alternative to MFMailComposeViewController?

is there an alternative to MFMailComposeViewController that has more-or-less the same functionality, but that will let me handle the sending of the email myself, outside of Apples email-sending system?
What I want to do is to provide a nice email dialog, and then send it through a CRM system instead of directly from the iPad.
Cheers
Nik
YES, You can use the MailCore Framework. You can handle the sending of email by yourself. Before sending the mail you have to set its fields such as To,CC,BCC,Subject,body etc and then send by the following code..
CTCoreMessage *msg = [[CTCoreMessage alloc] init];
[CTSMTPConnection sendMessage:msg server:[server stringValue] username:[username stringValue]
password:[password stringValue] port:[port intValue] useTLS:tls useAuth:auth];
[msg release];
It works for me fine. Hope it will help you..
You will need to create your own email view and handler. You can use something like JSTokenField : https://github.com/jasarien/JSTokenField to get the functionality on the mail "To:" field.

Resources