This is my code for getting device contacts and I want to move and copy these contacts to my Gmail Account.
CNContactStore *contactStore = [[CNContactStore alloc] init];
NSArray *keys = [[NSArray alloc]initWithObjects:CNContactJobTitleKey,CNContactNoteKey,CNContactBirthdayKey, CNContactThumbnailImageDataKey, CNContactPhoneNumbersKey,CNContactEmailAddressesKey,CNContactTypeKey, CNContactViewController.descriptorForRequiredKeys,CNContainerIdentifierKey, nil];
CNContactFetchRequest *request = [[CNContactFetchRequest alloc] initWithKeysToFetch:keys];
request.predicate = nil;
[contactStore enumerateContactsWithFetchRequest:request error:nil usingBlock:^(CNContact* __nonnull contact, BOOL* __nonnull stop){
}];
The most fundamental place you may want to check is Google Contacts API.
But for sure it's going to be time consuming and no easy. If that's not an option, you might consider to find something proper on GitHub.
Duraing a quick search I've found this library. Even if it doesn't do exactly what you need, you can get an insight how are you supposed to integrate the Google's API.
This is what you need to do if you decide to not use third-party libraries. (More details you can find here.):
1) you need to authorize;
2) after that you may send a request that creates a new contact:
POST /m8/feeds/contacts/default/full
Content-Type: application/atom+xml
GData-Version: 3.0
...
a request body:
<atom:entry xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:gd="http://schemas.google.com/g/2005">
<atom:category scheme="http://schemas.google.com/g/2005#kind"
term="http://schemas.google.com/contact/2008#contact"/>
<gd:name>
<gd:givenName>Elizabeth</gd:givenName>
<gd:familyName>Bennet</gd:familyName>
<gd:fullName>Elizabeth Bennet</gd:fullName>
</gd:name>
<atom:content type="text">Notes</atom:content>
<gd:email rel="http://schemas.google.com/g/2005#work"
primary="true"
address="liz#gmail.com" displayName="E. Bennet"/>
<gd:email rel="http://schemas.google.com/g/2005#home"
address="liz#example.org"/>
<gd:phoneNumber rel="http://schemas.google.com/g/2005#work"
primary="true">
(206)555-1212
</gd:phoneNumber>
<gd:phoneNumber rel="http://schemas.google.com/g/2005#home">
(206)555-1213
</gd:phoneNumber>
<gd:im address="liz#gmail.com"
protocol="http://schemas.google.com/g/2005#GOOGLE_TALK"
primary="true"
rel="http://schemas.google.com/g/2005#home"/>
<gd:structuredPostalAddress
rel="http://schemas.google.com/g/2005#work"
primary="true">
<gd:city>Mountain View</gd:city>
<gd:street>1600 Amphitheatre Pkwy</gd:street>
<gd:region>CA</gd:region>
<gd:postcode>94043</gd:postcode>
<gd:country>United States</gd:country>
<gd:formattedAddress>
1600 Amphitheatre Pkwy Mountain View
</gd:formattedAddress>
</gd:structuredPostalAddress>
</atom:entry>
Related
I use the following function to get the optimal route.
https://wse.ls.hereapi.com/2/findsequence.json?start=25.082621,121.583021&destination1=25.097258,121.517384&destination2=25.041825,121.514988&destination3=25.026060,121.527532&destination4=25.034607,121.488616&destination5=25.063467,121.539141&destination6=25.070833,121.531389&destination7=25.023056,121.505278&destination8=25.093102,121.532366&destination9=25.094807,121.529036&destination10=25.075230,121.560761&destination11=25.093102,121.532366&destination12=25.118899,121.470798&mode=fastest;car&&apiKey=...
And try to use this (HERE SDK FOR IOS (PREMIUM EDITION) V3.17) :
NMARoutingMode *routingMode = [[NMARoutingMode alloc] initWithRoutingType:NMARoutingTypeFastest transportMode:NMATransportModeScooter routingOptions:NMARoutingOptionAvoidHighway];
NMACoreRouter *coreRouter = [[NMACoreRouter alloc] init];
coreRouter.connectivity = NMACoreRouterConnectivityOnline;
[coreRouter calculateRouteWithStops:stops routingMode:routingMode completionBlock:^(NMARouteResult * _Nullable routeResult, NMARoutingError error) {
}];
to bring out NMARouteResult, but it only respond NMARoutingErrorInvalidOperation
How do I solve the problem?
The error indicates that another request is already being processed. Please make sure you are not calling the route calculation until the result of the previous request is returned.
I'm struggling to believe this is so difficult but after spending a couple of hours trying to figure it out, here I am asking the hive mind for help!
My question is very similar to this one however the answers in there don't help me as I have no keys in my form. I basically want to send a text .plist file from a PC to my app. The HTML on the page is this ..
<form action="/upload" method="post" enctype="multipart/form-data">
<input type="file" id="config" name="config" accept=".plist" size=40>
<input type="submit">
</form>
This gives a very simple form with a chose file button and a submit button. I have confirmed with Wireshark that the file is attached to the form and the thing is POSTed to the GCDWebServer in my app. I can also see the following confirming the body data as the file upload is processed by the web server:
[DEBUG] Connection on socket 21 preflighting request "POST /upload" with 2045 bytes body
[DEBUG] Connection on socket 21 processing request "POST /upload" with 2045 bytes body
My POST method for handling the file is this:
[_webServer addHandlerForMethod:#"POST"
path:#"/upload"
requestClass:[GCDWebServerRequest class]
processBlock:^GCDWebServerResponse *(GCDWebServerRequest* request) {
NSString *type = [(GCDWebServerRequest*)request contentType];
NSInteger length = [(GCDWebServerRequest*)request contentLength];
BOOL hasBody = [(GCDWebServerRequest*)request hasBody];
NSString *description = [(GCDWebServerURLEncodedFormRequest*)request description];
NSLog(#"\r\nType: %#\nLength: %lu\nHas Body: %#\nHeaders: %#\nConfig: %#", type, length, hasBody?#"YES":#"NO", description, #"");
return [GCDWebServerDataResponse responseWithHTML:#"TODO UPLOADED CONFIRMATION"];
}];
I can get the content type, content length, a boolean confirmation there is a body attached, all the headers and description of the boundaries etc. But I cannot for the life of me figure out how to get the actual body content. I don't wish to save it as a file I simply want it as an NSString so I can parse it and then save the settings inside my app.
A few things I have tried:
//NSData *data = [(GCDWebServerRequest*)request data];
//NSString *config = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
//NSString *config = [(GCDWebServerMultiPartFormRequest*)request files];
//NSString *config = [[(GCDWebServerURLEncodedFormRequest*)request arguments] objectForKey:#"filename"];
The NSData one looks the most likely to me but the app crashes when calling that. If anyone has any idea how I might access the body of this posted content I would be extremely grateful!
Thanks in advance!
Plasma
You'll want to use GCDWebServerMultiPartFormRequest. There's an an example here in https://github.com/swisspol/GCDWebServer/blob/master/Mac/main.m#L257.
I am using AWS MobileHub SDK with a developer authenticated identity setup.
The mobile hub SDK has an AWSIdentityManager that handles the session and
I have followed the guide here to login with my identity provider.
The identity provider works fine and the login succeeds but whenever I try to make a cloudlogic call (invoke a lambda function) to fails with:
AWSiOSSDKv2 [Error] AWSCloudLogic.m line:47 | __67-[AWSCloudLogic invokeFunction:withParameters:withCompletionBlock:]_block_invoke | invokeFunction: Error: The operation couldn’t be completed. AccessDeniedException
This indicates that when the lambda functions are being invoked that MobileHub is not using the correct AIM role and
Lambda is denying access. My AIM setup is fine and checked so I am not sure where the problem is.
In the AWSIdentityManager I have modified only this function:
- (AWSTask *)initializeClients:(NSDictionary *)logins {
NSLog(#"initializing clients...");
[AWSLogger defaultLogger].logLevel = AWSLogLevelError; //AWSLogLevelVerbose;
[AWSServiceConfiguration addGlobalUserAgentProductToken:AWS_MOBILEHUB_USER_AGENT];
NSString *email = [JNKeychain loadValueForKey:#"email"];
NSDictionary *logins = [NSDictionary dictionaryWithObject:email forKey:developerProvider];
id<AWSCognitoIdentityProvider> identityProvider = [[CBDeveloperAuthenticatedIdentityProvider alloc]
initWithRegionType:AMAZON_COGNITO_REGION
identityId:nil
identityPoolId:AMAZON_COGNITO_IDENTITY_POOL_ID
logins:logins
providerName:developerProvider];
self.credentialsProvider = [[AWSCognitoCredentialsProvider alloc]
initWithRegionType:AMAZON_COGNITO_REGION
identityProvider:identityProvider
unauthRoleArn:nil
authRoleArn:nil];
//I have AWS_COGNITO_UNAUTH_ROLE and AWS_COGNITO_AUTH_ROLE but the docs don't seem to use them... and when I do there is no change
//http://docs.aws.amazon.com/cognito/latest/developerguide/developer-authenticated-identities.html
AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AMAZON_COGNITO_REGION
credentialsProvider:self.credentialsProvider];
[AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;
return [self.credentialsProvider getIdentityId];
}
Amazon has a lot of information scattered everywhere but I couldn't find anything out there for mobile hub with regards to developer
authenticated identities but
I am trying to use Magento's api using SOAP request in iOS.
I am using SOAPEngine to make requests and retrieve the data.
I am able to login using the following code
self.soap = [[SOAPEngine alloc] init];
self.soap.userAgent = #"SOAPEngine";
self.soap.delegate = self; // use SOAPEngineDelegate
// each single value
[self.soap setValue:#"adminUserName" forKey:#"username"];
[self.soap setValue:#"adminPassword" forKey:#"apiKey"];
// service url without ?WSDL, and you can search the soapAction in the WSDL
[self.soap requestURL:#"http://192.168.1.50/projects/usapool/api/"
soapAction:#"http://192.168.1.50/projects/usapool/api/login"];
but when I try to call the catalog_product.list as mentioned on catalog_product.list API with filters as follows
NSMutableDictionary *filterDictionary = [[NSMutableDictionary alloc] init];
[filterDictionary setValue:#"28" forKey:#"product_id"];
// each single value
[self.soap setValue:sessionId forKey:#"sessionId"];
[self.soap setValue:#"catalog_product.list" forKey:#"resourcePath"];
[self.soap setValue:filterDictionary forKey:#"filters"];
// service url without ?WSDL, and you can search the soapAction in the WSDL
[self.soap requestURL:#"http://192.168.1.50/projects/usapool/api/"
soapAction:#"http://192.168.1.50/projects/usapool/api/call"];
I get the array of all the products and filter is not applied.
Does anybody know how to apply the filters in this case?
I am using following code to handle twitter integration in my Application.
- (IBAction)signInWithTwitter:(id)sender {
NSURL *requestURL = [NSURL URLWithString:#"https://api.twitter.com/oauth/request_token"];
NSURL *accessURL = [NSURL URLWithString:#"https://api.twitter.com/oauth/access_token"];
NSURL *authorizeURL = [NSURL URLWithString:#"https://api.twitter.com/oauth/authorize"];
NSString *scope = #"http://api.twitter.com/";
GTMOAuthAuthentication *auth = [self authForTwitter];
[auth setCallback:#"http://www.noop.com/OAuthCallback"];
GTMOAuthViewControllerTouch *viewController;
viewController = [[GTMOAuthViewControllerTouch alloc] initWithScope:scope
language:nil
requestTokenURL:requestURL
authorizeTokenURL:authorizeURL
accessTokenURL:accessURL
authentication:auth
appServiceName:#"CK12: Twitter"
delegate:self
finishedSelector:#selector(viewController:finishedWithAuth:error:)];
}
- (GTMOAuthAuthentication *)authForTwitter {
GTMOAuthAuthentication *auth = [[GTMOAuthAuthentication alloc] initWithSignatureMethod:kGTMOAuthSignatureMethodHMAC_SHA1
consumerKey:TWITTER_CONSUMER_KEY
privateKey:TWITTER_CONSUMER_SECRET];
[auth setServiceProvider:#"Twitter"];
return auth;
}
My problem is, if I am changing device time i.e making it 1 hour late, then I am getting following error:
Error Domain=com.google.HTTPStatus Code=401 and error message is : failed to validate oauth signature and token .
So can anybody please suggest how to solve this. if system time is wrong then also I want to make it work .
Finally I got solution for this . . . .
One of the reason we get this error "Failed to validate OAuth signature and token"
when system time is wrong . Because OAuth request carry system timestamp parameters with it , so when device time is not within the 5 minutes of twitter server time .we get "Failed to validate OAuth signature and token" .
There are two ways to make it work , if the device time is even wrong .
1.make HTTP HEAD request to an endpoint on api.twitter.com -- you'll get a Date HTTP header in the response that indicates the current time understood by Twitter. You would then convert this to epoch time and adjust your oauth_timestamp values by a determined offset.
2.There's a small iOS library named ios-ntp link: http://code.google.com/p/ios-ntp . use this to get the current Accurate time .
After that i just set the timestamp of OAuth object in the following method
- (GTMOAuthAuthentication *)authForTwitter
{
GTMOAuthAuthentication *auth = [[GTMOAuthAuthentication alloc]
initWithSignatureMethod:kGTMOAuthSignatureMethodHMAC_SHA1
consumerKey:TWITTER_CONSUMER_KEY
privateKey:TWITTER_CONSUMER_SECRET];
[auth setServiceProvider:#"Twitter"];
NSDate * currentdate = //GET ACCURATE DATE HERE ;
[auth setTimestamp:[NSString stringWithFormat:#"%f",[currentdate timeIntervalSince1970]]];
return auth;
}
that's it . . .Happy Coding :)