I'm using Google places api for iOS.I've implemented current place feature. Here's the code(it's same as google provided in guide).
[_placesClient currentPlaceWithCallback:^(GMSPlaceLikelihoodList *likelihoodList, NSError *error) {
if (error != nil) {
NSLog(#"Current Place error %#", [error localizedDescription]);
return;
}
for (GMSPlaceLikelihood *likelihood in likelihoodList.likelihoods) {
GMSPlace* place = likelihood.place;
NSLog(#"Current Place name %# at likelihood %g", place.name, likelihood.likelihood);
NSLog(#"Current Place address %#", place.formattedAddress);
NSLog(#"Current Place attributions %#", place.attributions);
NSLog(#"Current PlaceID %#", place.placeID);
}
}];
but it takes about 3-4 minutes to execute the callback. I've followed all the steps they provided in guide.
Related
I want to share a post on Pintrest( i.e. want to pin from my app). I have used its SDK using Cocoa Pod. I'm able to pin (share) sometimes but sometimes while pinning it app crashes on random basis and getting nothing in crash log.
Can anyone tell me what is going wrong ? I'm adding the code snippet that i have used...I have used this link to install the SDK and followed this link. https://github.com/pinterest/ios-pdk
-(IBAction)pintrestButtonTapped
{
#try
{
[PDKClient configureSharedInstanceWithAppId:#"4841203782190640720"];
[[PDKClient sharedInstance] authenticateWithPermissions:#[PDKClientReadPublicPermissions,
PDKClientWritePublicPermissions,
PDKClientReadPrivatePermissions,
PDKClientWritePrivatePermissions,
PDKClientReadRelationshipsPermissions,
PDKClientWriteRelationshipsPermissions]
withSuccess:^(PDKResponseObject *responseObject)
{
[PDKPin pinWithImageURL:[NSURL URLWithString:#"https://www.respectnetwork.com/wp-content/uploads/cynja-app_store_share.jpg"]
link:[NSURL URLWithString:#"https://itunes.apple.com/us/app/cynjaspace/id1050628761?ls=1&mt=8/"]
suggestedBoardName:#"CynzaSpace"
note:kSocialMediaSharingText
withSuccess:^
{
NSLog(#"Successfully Pinned Up!!");
}
andFailure:^(NSError *error)
{
NSLog(#"UnSuccessfull");
}];
}
andFailure:^(NSError *error)
{
NSLog(#"authentication failed: %#", error);
}];
}
#catch (NSException *exception)
{
// Print exception information
NSLog( #"NSException caught" );
NSLog( #"Name: %#", exception.name);
NSLog( #"Reason: %#", exception.reason );
return;
}
}
I am trying to get current place based on google place API iOS, other API for place picker, add place is calling callback methods, but when i am trying to get current place with below code, it not giving any error or not even calling callback method.
_placesClient = [GMSPlacesClient sharedClient];
[_placesClient currentPlaceWithCallback:^(GMSPlaceLikelihoodList *likelihoodList, NSError *error) {
if (error != nil) {
NSLog(#"Current Place error %#", [error localizedDescription]);
return;
}
int cnt =0;
for (GMSPlaceLikelihood *likelihood in likelihoodList.likelihoods) {
cnt++;
if(cnt==1)
{
GMSPlace* place = likelihood.place;
NSLog(#"Current Place name %# at likelihood %g", place.name, likelihood.likelihood);
NSLog(#"Current Place address %#", place.formattedAddress);
NSLog(#"Current Place attributions %#", place.attributions);
NSLog(#"Current PlaceID %#", place.placeID);
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(place.coordinate.latitude,place.coordinate.longitude);
// CLLocationCoordinate2D center = CLLocationCoordinate2DMake([lat doubleValue],[lng doubleValue]);
CLLocationCoordinate2D northEast = CLLocationCoordinate2DMake(center.latitude + 0.001, center.longitude + 0.001);
CLLocationCoordinate2D southWest = CLLocationCoordinate2DMake(center.latitude - 0.001, center.longitude - 0.001);
GMSCoordinateBounds *viewport = [[GMSCoordinateBounds alloc] initWithCoordinate:northEast
coordinate:southWest];
GMSPlacePickerConfig *config = [[GMSPlacePickerConfig alloc] initWithViewport:viewport];
_placePicker = [[GMSPlacePicker alloc] initWithConfig:config];
[_placePicker pickPlaceWithCallback:^(GMSPlace *place, NSError *error) {
if (error != nil) {
NSLog(#"Pick Place error %#", [error localizedDescription]);
}
if (place != nil) {
[_placesClient reportDeviceAtPlaceWithID:place.placeID];
NSLog(#"Place name %#", place.name);
NSLog(#"Place address %#", place.formattedAddress);
NSLog(#"Place placeID %#", place.placeID);
NSLog(#"Place number %#", place.phoneNumber);
NSLog(#"Place website %#", place.website);
self.placeInfo = [[SHPlaceInfo alloc]init];
self.placeInfo.address=place.formattedAddress;
self.placeInfo.phnNumber=place.phoneNumber;
self.placeInfo.website = [NSString stringWithFormat:#"%#",place.website];
self.placeInfo.idStr = place.placeID;
self.placeInfo.lat =[NSString stringWithFormat:#"%f", place.coordinate.latitude];
self.placeInfo.lng =[NSString stringWithFormat:#"%f", place.coordinate.longitude];
self.placeInfo.type = [place.types componentsJoinedByString:#","];
self.placeInfo.name = place.name;
[self savePlaceDatainDatabase:self.placeInfo];
// [self getNearDetailPlaces];
//if place id gives phone number then need to use below flow and remove api call above getNearDetailPlaces
selectedPlaceDetailViewController *placeDetailVC=[self.storyboard instantiateViewControllerWithIdentifier:#"selectedPlaceDetailViewController"];
placeDetailVC.placeInfo = self.placeInfo;
placeDetailVC.strCalledFromPage=#"Home";
[self.navigationController pushViewController: placeDetailVC animated:YES];
} else {
NSLog(#"No place selected");
}
}];
}
}
}];
One possibility: you might not be retaining a reference to _placesClient.
The outstanding callback alone won't keep the GMSPlacesClient instance alive, so if you don't ensure your program keeps a reference to it the callback might never be fired, which matches the symptom you see.
I am not sure with exact issue, but after running this in iPhone6 its calling that callback method,it can be issue of OS version also.Google Place API for iOS is only supported in latest version of OS.and i have got this spark from #ZeMoon's answer.
Thank you all for reply
I had the same issue, and just like you it seems to work only on iPhone 6 simulator and up, so it is probably due to the assumed iOS version on the simulated devices.
I want to delete all HKQuantitySamples that my app has saved in the Health App for a certain HKQuantityType, how would I do that?
I can see the function
deleteObject:withCompletion:
in the Apple Documentation, but I do not really understand how to use it. Can somebody show an example maybe?
EDIT: I now use the following code for deleting:
I have saved my food information as a HKCorrelation and set my Local Food ID in the Correlations metadata HKMetadataKeyExternalUUID key.
For deletion I am fetching all the HKCorrelation objects between startDate and endDate and then if one of these fetched objects matches the Local Food ID I am looking for:
- I delete every object in that Correlation,
- Followed by deleting the Correlation itself
HKCorrelationType *foodType = [HKObjectType correlationTypeForIdentifier:HKCorrelationTypeIdentifierFood];
NSPredicate *predicate = [HKQuery predicateForSamplesWithStartDate:startDate endDate:endDate options:HKQueryOptionNone];
HKSampleQuery *query = [[HKSampleQuery alloc] initWithSampleType:foodType predicate:predicate limit:HKObjectQueryNoLimit sortDescriptors:nil resultsHandler:^(HKSampleQuery *query, NSArray *results, NSError *error) {
if (!results) {
NSLog(#"An error occured fetching the user's tracked food. In your app, try to handle this gracefully. The error was: %#.", error);
return;
}
dispatch_async(dispatch_get_main_queue(), ^{
for (HKCorrelation *foodCorrelation in results) {
if([[foodCorrelation.metadata valueForKey:HKMetadataKeyExternalUUID] isEqualToString:food_id_I_want_to_delete]) {
NSSet *objs = foodCorrelation.objects;
for (HKQuantitySample *sample in objs) {
[self.healthStore deleteObject:sample withCompletion:^(BOOL success, NSError *error) {
if (success) {
NSLog(#"Success. delete sample");
}
else {
NSLog(#"delete: An error occured deleting the sample. In your app, try to handle this gracefully. The error was: %#.", error);
}
}];
}
[self.healthStore deleteObject:foodCorrelation withCompletion:^(BOOL success, NSError *error) {
if (success) {
NSLog(#"Success. delete %#", [foodCorrelation.metadata valueForKey:HKMetadataKeyExternalUUID]);
}
else {
NSLog(#"delete: An error occured deleting the Correlation. In your app, try to handle this gracefully. The error was: %#.", error);
}
}];
return;
}
}
});
}];
[self.healthStore executeQuery:query];
I'm developing a simple app that has a feature to compose user pictures and post them as a OG Story to facebook.
I followed the Facebook docs and I'm issuing the POST requests (I know I could batch them, I'm just trying to get any version working), I do get an story ID, but I can't find the story on Facebook. (permission set to friends)
I'm posting it with the path /me/:
When I check in the Graph Explorer this path returns an empty { 'data' : [] }
I know the story won't be posted on my profile, but I need to see it somewhere.
I need to test things such as deep linking (I know url is currently set to nil), but I can't find the story! The only place I could manage to see the picture is when I go to
developer page and click on 'preview'.
Any ideas?
Thanks in advance.
Here is the source code:
- (void) publishPhoto
{
// stage an image
[FBRequestConnection startForUploadStagingResourceWithImage:self.photo.image completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error) {
NSLog(#"Successfuly staged image with staged URI: %#", [result objectForKey:#"uri"]);
// instantiate a Facebook Open Graph object
NSMutableDictionary<FBOpenGraphObject> *object = [FBGraphObject openGraphObjectForPostWithType:#"<APPNAMESPACE>:picture" title:#"" image:#[#{#"url":[result objectForKey:#"uri"], #"user_generated" : #"true"}] url:nil description:#""];
// Post custom object
[FBRequestConnection startForPostOpenGraphObject:object completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error) {
// get the object ID for the Open Graph object that is now stored in the Object API
NSString *objectId = [result objectForKey:#"id"];
NSLog([NSString stringWithFormat:#"object id: %#", objectId]);
// create an Open Graph action
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
[action setObject:objectId forKey:#"picture"];
// create action referencing user owned object
[FBRequestConnection startForPostWithGraphPath:#"/me/<APPNAMESPACE>:take" graphObject:action completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error) {
NSLog([NSString stringWithFormat:#"OG story posted, story id: %#", [result objectForKey:#"id"]]);
[[[UIAlertView alloc] initWithTitle:#"OG story posted"
message:#"Check your Facebook profile or activity log to see the story."
delegate:self
cancelButtonTitle:#"OK!"
otherButtonTitles:nil] show];
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(#"Encountered an error posting to Open Graph: %#", error.description);
}
}];
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(#"Encountered an error posting to Open Graph: %#", error.description);
}
}];
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(#"Error staging an image: %#", error.description);
}
}];
}
Try it with iPhone device instead of simulator. It'll work
I want to get tweets list using Twitter Search API. But Recently twitter has launched New version-1.1 and it requires authorization. I'm using STTwitter library for interacting with Twitter API.
I'm using STTwitter_ios project which you can find from here :
https://github.com/nst/STTwitter/tree/master/ios
Now, I have written one sample function: fetchTweets. Authorization works successful and I'm getting the list if i search for the word (Without spaces or special characters). But When I try to search keyword with spaces or Special characters like "New york", #"New or York", etc.. then it returns error :
In the method ,
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
I'm getting error :
{"errors":[{"message":"Could not authenticate you","code":32}]}
- (void) fetchTweets {
STTwitterAPIWrapper *twitter = [STTwitterAPIWrapper twitterAPIWithOAuthConsumerName:OAUTH_CONSUMER_NAME consumerKey:OAUTH_CONSUMER_KEY consumerSecret:OAUTH_CONSUMER_SECRET oauthToken:OAUTH_TOKEN oauthTokenSecret:OAUTH_SECRET_TOKEN];
NSString *query = #"New york";
NSString *searchQuery = [query stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[twitter getSearchTweetsWithQuery:searchQuery successBlock:^(NSDictionary *searchMetadata, NSArray *statuses) {
NSLog(#"Search data : %#",searchMetadata);
NSLog(#"\n\n Status : %#",statuses);
} errorBlock:^(NSError *error) {
NSLog(#"Error : %#",error);
}];
}
Any help or suggestions will be appreciated !
Thanks !
Finally, I removed OAuth token and it works fine !
See code below :
STTwitterAPIWrapper *twitter = [STTwitterAPIWrapper twitterAPIApplicationOnlyWithConsumerKey:OAUTH_CONSUMER_KEY consumerSecret:OAUTH_CONSUMER_SECRET];
[twitter verifyCredentialsWithSuccessBlock:^(NSString *username) {
[twitter getSearchTweetsWithQuery:searchQuery successBlock:^(NSDictionary *searchMetadata, NSArray *statuses) {
NSLog(#"Search data : %#",searchMetadata);
NSLog(#"\n\n Status : %#",statuses);
} errorBlock:^(NSError *error) {
NSLog(#"Error : %#",error);
}];
} errorBlock:^(NSError *error) {
NSLog(#"-- error %#", error);
}];
I am Nicolas Seriot the creator of STTwitter.
The issue you encountered was a bug and I just fixed it.
Try to add HTML encode the keywords. For example with
[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]