iPhone netword SSID - iphone

I am having issues implementing the code from the answer on this question: iPhone get SSID without private library
I have xcode 4.2 and iOS 5.1.
#import <SystemConfiguration/CaptiveNetwork.h>
- (id)fetchSSIDInfo
{
NSArray *ifs = (id)CNCopySupportedInterfaces();
NSLog(#"%s: Supported interfaces: %#", __func__, ifs);
id info = nil;
for (NSString *ifnam in ifs) {
info = (id)CNCopyCurrentNetworkInfo((CFStringRef)ifnam);
NSLog(#"%s: %# => %#", __func__, ifnam, info);
if (info && [info count]) {
break;
}
[info release];
}
[ifs release];
return [info autorelease];
}
I get the following errors:
What am I doing wrong?

You need to add CFNetwork.framework to your project.
You can do it by selecting Targets > Summary> Linked Framework and Libraries.

Related

lazy symbol binding failed: Symbol not found Error with iOS - GDrive Integration

I saw the video at GDrive Quickstart iOS Page (https://developers.google.com/drive/quickstart-ios). I followed it step by step, re-tried several times in my iPhone App, & even watched the video. Am trying to integrate GDrive into my existing iphone App.
I imported GTMOAuth2ViewControllerTouch.h & GTLDrive.h & added this to my .h file :
#property (nonatomic, strong) GTLServiceDrive *driveService;
In .m :
// Helper to check if user is authorized
- (BOOL)isAuthorized
{
return [((GTMOAuth2Authentication *)self.driveService.authorizer) canAuthorize];
}
// Handle completion of the authorization process, and updates the Drive service
// with the new credentials.
- (void)viewController:(GTMOAuth2ViewControllerTouch *)viewController
finishedWithAuth:(GTMOAuth2Authentication *)authResult
error:(NSError *)error
{
if (error != nil)
{
NSLog(#"Authentication Error - %#", error.localizedDescription);
self.driveService.authorizer = nil;
}
else
{
self.driveService.authorizer = authResult;
}
}
-(void) uploadFile : (NSString *) appFile {
NSLog(#"uploadFile %#", appFile);
// Initialize the drive service & load existing credentials from the keychain if available
self.driveService = [[GTLServiceDrive alloc] init];
self.driveService.authorizer = [GTMOAuth2ViewControllerTouch
authForGoogleFromKeychainForName : kGDriveKeychainItem
clientID : kGDriveClientID
clientSecret : kGDriveClientSecret];
NSLog(#"auth done");
GTLDriveFile *file = [GTLDriveFile object];
file.title = fileStat;
file.descriptionProperty = #"App Info";
file.mimeType = #"text/plain";
NSData *data = [NSData dataWithContentsOfFile : appFile];
GTLUploadParameters *uploadParameters = [GTLUploadParameters uploadParametersWithData:data MIMEType:file.mimeType];
GTLQueryDrive *query = [GTLQueryDrive queryForFilesInsertWithObject:file
uploadParameters:uploadParameters];
NSLog(#"Uploading to GDrive");
[self.driveService executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
GTLDriveFile *insertedFile, NSError *error) {
if (error == nil)
{
NSLog(#"File ID: %# ; GDrive file saved!", insertedFile.identifier);
}
else
{
NSLog(#"GDrive - An error occurred: %#", error);
}
}];
}
Am getting the error
dyld: lazy symbol binding failed: Symbol not found: _objc_setProperty_nonatomic_copy
Expected in: /usr/lib/libobjc.A.dylib
after the line "upload file" (it prints this line & then crashes).
Can someone please help?

GData Objective-C Client Contact Service

I downloaded the last GData client via SVN https://code.google.com/p/gdata-objectivec-client/
I succesfully compiled it and I integrated successfully the static library inside my project.
I need to retrieve all gmail contacts about a google username:
- (GDataServiceGoogleContact *)contactService {
static GDataServiceGoogleContact* service = nil;
if (!service) {
service = [[GDataServiceGoogleContact alloc] init];
[service setShouldCacheResponseData:YES];
[service setServiceShouldFollowNextLinks:YES];
}
// update the username/password each time the service is requested
NSString *username = usr.text;
NSString *password = psw.text;
[service setUserCredentialsWithUsername:username
password:password];
return service;
}
- (IBAction)getContacts:(id)sender; {
GDataServiceGoogleContact *gc =[self contactService];
NSURL *feedURL = [GDataServiceGoogleContact contactFeedURLForUserID:usr.text];
GDataServiceTicket *ticket;
ticket = [gc fetchFeedWithURL:feedURL
delegate:self
didFinishSelector:#selector(ticket:finishedWithFeed:error:)];
[self startLoading];
}
The callback selector looks like this:
- (void)ticket:(GDataServiceTicket *)ticket finishedWithFeed:(GDataFeedContact *)feed
error:(NSError *)error {
[self stopLoading];
if (error == nil) {
NSArray *entries = [NSArray arrayWithArray:[feed entries]];
if ([entries count] > 0) {
for (GDataEntryContact *firstContact in entries) {
NSString *name = [((GDataNameElement*)[[firstContact name] fullName]) stringValue];
NSString *email = ([firstContact emailAddresses] != nil && [[firstContact emailAddresses] count]!=0) ? [[[firstContact emailAddresses] objectAtIndex:0] stringValueForAttribute:#"address"]: NSLocalizedString(#"not found",#"");
if (name == nil) {
name = email;
}
BBGmailContact *tmpContact = [[BBGmailContact alloc] initWithName:name email:email];
[contacts addObject:tmpContact];
[self.navigationController popViewControllerAnimated:YES];
}
[gmailDelegate contactsDidDownload:contacts];
} else {
[self createAlertView:NSLocalizedString(#"Warning", #"") message:NSLocalizedString(#"No contact found", #"")];
}
} else {
[self createAlertView:NSLocalizedString(#"Error", #"Error") message:NSLocalizedString(#"Please, check your user and password", #"")];
}
}
Why is every entry of entries a kind of class: GDataEntryBase instead GDataEntryContact?
Where is my error? Can someone help me?
Entries are created as GDataEntryBase if the application does not have the service-specific classes for Contacts compiled and linked into the app.
Be sure too that the appropriate build flags for the Contacts service are specified as described in the docs.

How to get user details using twitter api v1.1 (Twitter error 215)

I have used the twitter api provided by twitter,to get the details but
not able to execute it, even tried to pass the authentication data
like consumer secret key, consumer key, token but the result is same.
I am able to login and receiving twitter authentication token but not able to get user details.
Below code is used by me (I am using MGtwitter engine) :
NSMutableURLRequest *request =[[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:[NSString stringWithFormat:#"https://api.twitter.com/1.1/users/show.json?screen_name=%#",username]]];
NSData *returnData = [ NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil ];
NSString *returnString = [[NSString alloc]initWithData:returnData encoding:NSUTF8StringEncoding];
NSError *err = nil;
twitterLogin = [NSJSONSerialization JSONObjectWithData:[returnString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:&err];
Error is shown as below:
errors = (
{
code = 215;
message = "Bad Authentication data";
} );
First, you need to Authenticate your request (Get permission).
second, see follow these steps:
1.Download FHSTwitterEngine Twitter Library.
2.Add the folder FHSTwitterEngine" to your project and #import "FHSTwitterEngine.h".
3.add SystemConfiguration.framework to your project.
Usage : 1.in the [ViewDidLoad] add the following code.
UIButton *logIn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
logIn.frame = CGRectMake(100, 100, 100, 100);
[logIn setTitle:#"Login" forState:UIControlStateNormal];
[logIn addTarget:self action:#selector(showLoginWindow:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:logIn];
[[FHSTwitterEngine sharedEngine]permanentlySetConsumerKey:#"<consumer_key>" andSecret:#"<consumer_secret>"];
[[FHSTwitterEngine sharedEngine]setDelegate:self];
and don't forget to import the delegate FHSTwitterEngineAccessTokenDelegate.
you need to get the permission for your request, with the following method which will present Login window:
- (void)showLoginWindow:(id)sender {
[[FHSTwitterEngine sharedEngine]showOAuthLoginControllerFromViewController:self withCompletion:^(BOOL success) {
NSLog(success?#"L0L success":#"O noes!!! Loggen faylur!!!");
}];
}
when the Login window is presented, enter your Twitter Username and Password to authenticate your request.
add the following methods to your code:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[FHSTwitterEngine sharedEngine]loadAccessToken];
NSString *username = [[FHSTwitterEngine sharedEngine]loggedInUsername];// self.engine.loggedInUsername;
if (username.length > 0) {
lbl.text = [NSString stringWithFormat:#"Logged in as %#",username];
[self listResults];
} else {
lbl.text = #"You are not logged in.";
}
}
- (void)storeAccessToken:(NSString *)accessToken {
[[NSUserDefaults standardUserDefaults]setObject:accessToken forKey:#"SavedAccessHTTPBody"];
}
- (NSString *)loadAccessToken {
return [[NSUserDefaults standardUserDefaults]objectForKey:#"SavedAccessHTTPBody"];
}
4.Now you are ready to get your request, with the following method(in this method I created a Twitter search for some Hashtag, to get the screen_name for example):
- (void)listResults {
dispatch_async(GCDBackgroundThread, ^{
#autoreleasepool {
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
// the following line contains a FHSTwitterEngine method wich do the search.
dict = [[FHSTwitterEngine sharedEngine]searchTweetsWithQuery:#"#iOS" count:100 resultType:FHSTwitterEngineResultTypeRecent unil:nil sinceID:nil maxID:nil];
// NSLog(#"%#",dict);
NSArray *results = [dict objectForKey:#"statuses"];
// NSLog(#"array text = %#",results);
for (NSDictionary *item in results) {
NSLog(#"text == %#",[item objectForKey:#"text"]);
NSLog(#"name == %#",[[item objectForKey:#"user"]objectForKey:#"name"]);
NSLog(#"screen name == %#",[[item objectForKey:#"user"]objectForKey:#"screen_name"]);
NSLog(#"pic == %#",[[item objectForKey:#"user"]objectForKey:#"profile_image_url_https"]);
}
dispatch_sync(GCDMainThread, ^{
#autoreleasepool {
UIAlertView *av = [[UIAlertView alloc]initWithTitle:#"Complete!" message:#"Your list of followers has been fetched" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[av show];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
});
}
});
}
That's all.
I just got the screen_name from a search Query, you can get a timeline for a user using the following methods:
// statuses/user_timeline
- (id)getTimelineForUser:(NSString *)user isID:(BOOL)isID count:(int)count;
- (id)getTimelineForUser:(NSString *)user isID:(BOOL)isID count:(int)count sinceID:(NSString *)sinceID maxID:(NSString *)maxID;
instead of the search method above.
Note: see the FHSTwitterEngine.h to know what method you need to use.
Note: to get the <consumer_key> and the <consumer_secret> you need to to visit this link
to register your app in Twitter.
Got the solution after MKAlatrash revert, to get the user profile follow certain steps in the code as under :
[[FHSTwitterEngine sharedEngine]getProfileImageForUsername:username andSize:FHSTwitterEngineImageSizeNormal];
jump to definition of this function and replace the if ... else if part
if ([userShowReturn isKindOfClass:[NSError class]]) {
return [NSError errorWithDomain:[(NSError *)userShowReturn domain] code:[(NSError *)userShowReturn code] userInfo:[NSDictionary dictionaryWithObject:request forKey:#"request"]];
NSLog(#"user show return %#",userShowReturn);
} else if ([userShowReturn isKindOfClass:[NSDictionary class]]) {
return userShowReturn;
NSString *url = [userShowReturn objectForKey:#"profile_image_url"]; // normal
if (size == 0) { // mini
url = [url stringByReplacingOccurrencesOfString:#"_normal" withString:#"_mini"];
} else if (size == 2) { // bigger
url = [url stringByReplacingOccurrencesOfString:#"_normal" withString:#"_bigger"];
} else if (size == 3) { // original
url = [url stringByReplacingOccurrencesOfString:#"_normal" withString:#""];
}
id ret = [self sendRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
if ([ret isKindOfClass:[NSData class]]) {
return [UIImage imageWithData:(NSData *)ret];
}
return ret;
}
That really was helpful thanks

Issue With selecting multiple images

How to detect total available/free disk space on the iPhone/iPad device?
I assume that clicking that "done" button would invoke cancelling the picker; in which case you can try did you try implementing the delegate method:
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissViewControllerAnimated:YES completion:^(void) {
NSLog(#"Cancelled pick");
};
}
Also it looks like you're calling release -- any reason you're not using ARC?
If I had to guess, I'd say perhaps the alert dismiss is in fact calling something like
[imagePicker.delegate imagePickerControllerDidCancel:imagePicker];
but it's already released so you're seeing this "lock-up" issue. Maybe step through in the debugger and make sure those objects still exist.
Edit:
While it doesn't solve your original issue, you could do a check for available space prior to launching the image picker, possibly with something like this so post suggests:
- (uint64_t)freeDiskspace
{
uint64_t totalSpace = 0;
uint64_t totalFreeSpace = 0;
__autoreleasing NSError *error = nil;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
if (dictionary) {
NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemSize];
NSNumber *freeFileSystemSizeInBytes = [dictionary objectForKey:NSFileSystemFreeSize];
totalSpace = [fileSystemSizeInBytes unsignedLongLongValue];
totalFreeSpace = [freeFileSystemSizeInBytes unsignedLongLongValue];
NSLog(#"Memory Capacity of %llu MiB with %llu MiB Free memory available.", ((totalSpace/1024ll)/1024ll), ((totalFreeSpace/1024ll)/1024ll));
} else {
NSLog(#"Error Obtaining System Memory Info: Domain = %#, Code = %d", [error domain], [error code]);
}
return totalFreeSpace;
}

How to get the device name programmatically in iPhone sdk?

i get the device Mac and IP Address. But, don't get the device name.
any idea how to get more info if possible like "Network Utility" of device ?
NSLog(#"uniqueIdentifier: %#", [[UIDevice currentDevice] uniqueIdentifier]);
NSLog(#"name: %#", [[UIDevice currentDevice] name]);
NSLog(#"systemName: %#", [[UIDevice currentDevice] systemName]);
NSLog(#"systemVersion: %#", [[UIDevice currentDevice] systemVersion]);
NSLog(#"model: %#", [[UIDevice currentDevice] model]);
NSLog(#"localizedModel: %#", [[UIDevice currentDevice] localizedModel]);
On iOS 4.1+, you can do this: If you are looking for SSID Name..
import
- (id)fetchSSIDInfo
{
NSArray *ifs = (id)CNCopySupportedInterfaces();
NSLog(#"%s: Supported interfaces: %#", __func__, ifs);
id info = nil;
for (NSString *ifnam in ifs) {
info = (id)CNCopyCurrentNetworkInfo((CFStringRef)ifnam);
NSLog(#"%s: %# => %#", __func__, ifnam, info);
if (info && [info count]) {
break;
}
[info release];
}
[ifs release];
return [info autorelease];
}
#import <ifaddrs.h>
#import <arpa/inet.h>
- (NSString *)getIPAddress {
NSString *address = #"error";
struct ifaddrs *interfaces = NULL;
struct ifaddrs *temp_addr = NULL;
int success = 0;
// retrieve the current interfaces - returns 0 on success
success = getifaddrs(&interfaces);
if (success == 0) {
// Loop through linked list of interfaces
temp_addr = interfaces;
while(temp_addr != NULL) {
if(temp_addr->ifa_addr->sa_family == AF_INET) {
// Check if interface is en0 which is the wifi connection on the iPhone
if([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:#"en0"]) {
// Get NSString from C String
address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];
}
}
temp_addr = temp_addr->ifa_next;
}
}
// Free memory
freeifaddrs(interfaces);
return address;
}