Getting user's default email address in Cocoa - objective-c

How do I obtain the user's default email address? I need to obtain it for my crash reporter dialog, so the user won't have to fill it out manually.

Never mind, I got it. First, I just have to add AddressBook.framework into my Linked Frameworks. Then, this is the code required:
#import <AddressBook/AddressBook.h>
NSString *theEmailAddressWeWantToObtain = #"";
ABPerson *aPerson = [[ABAddressBook sharedAddressBook] me];
ABMultiValue *emails = [aPerson valueForProperty:kABEmailProperty];
if([emails count] > 0)
theEmailAddressWeWantToObtain = [emails valueAtIndex:0];

From "*Address Book Programming Guide for iOS":
Link the Address Book UI and Address Book frameworks to your project.
Important The project will fail to build (with a linker error) if you do not link against both of these framework.
Linking in the Framework without the UI will prevent the sample code from compiling.

Related

How could i add phonebook contacts to my chat app in ios by using xmpp framework and openfire server?

I am new to chat application and making it in objective-c. I wanted to know how could i save all my phonebook contacts as user. i know how to fetch contacts from address book but dont have much idea about xmpp framework and openfire.If anyone could help me.
First you know how to fetch contacts.now every contact you need to add Xmpp Roaster.like below
call this method called at your contact fetching class.
[[self appDelegate] addNewBuddyToMyAccount:tempNumber withNickName:[[tempContactList objectAtIndex:i] fullname]];
//in my terms tempNumber is the phone number that is JID.
in your xmpp class follow below code to add to roster
NSString * buddyNameJID = [NSString stringWithFormat:#"%##serverName",buddyUserID];
XMPPJID *jid = [XMPPJID jidWithString:buddyNameJID];
//if you don't need permission then use below line otherwise comment
[[self xmppRoster] acceptPresenceSubscriptionRequestFrom:jid andAddToRoster:YES];
//here we are adding our contact to our roster then check once in roaster in openfire
[[self xmppRoster] addUser:jid withNickname:nickName];
hope this helps.

Why is compiler reporting SDWebImageManager defaultCachePathForKey not found?

I am seeing the compiler warn that "Instance method -cacheKeyForURL not found" and "Instance method -defaultCachePathForKey not found", in the following code:
SDWebImageManager *manager = [SDWebImageManager sharedManager];
NSString *cacheKey = [manager cacheKeyForURL:[NSURL URLWithString:imageUrl]];
NSString *cachePath = [[manager imageCache] defaultCachePathForKey:cacheKey];
Yet clearly, these methods are defined. Here, for example, is the method definition in SDImageCache.h:
/**
* Get the default cache path for a certain key
*
* #param key the key (can be obtained from url using cacheKeyForURL)
*
* #return the default cache path
*/
- (NSString *)defaultCachePathForKey:(NSString *)key;
At the top of my code file, I am including the relevant files from the SDWebImage project:
#import <SDWebImage/UIImageView+WebCache.h>
#import <SDWebImage/SDImageCache.h>
#import <SDWebImage/SDWebImageManager.h>
Moreover, sharedImageManager is defined in SDWebImageManager.h and the compiler is having no problems finding it. I only have warnings on the 2nd and 3rd lines.
My code runs fine and these methods both work without crashing. Why is the compiler telling me it cannot find it?
I am running XCode 6, compiling for Active Architecture Only, iPhone 6 Simulator.
UPDATE
When I compile for Distribution, "All Architectures", suddenly it can find cacheKeyForURL and defaultCachePathForKey, no problem, but setImageWithURL is now deprecated?
I do see the deprecation warnings in UIImageView+WebCache.h, but I'm just super-confused why building for these different architectures is turning on/off various compiler warnings when the header files of SDWebImage don't seem to have anything architecture-specific to them.
I figured this out by more closely inspecting the error in the "Report Navigator" (neé Log Navigator).
It turns out that there were some very old SDWebImageManager.h files in the "Derived Data" folder that it was choosing to link against. Unclear why they did not go away upon a clean of my project. (Possibly connected to the fact that I migrated from submodules to including SDWebImage via Cocoapods?)
I used this answer on Stack Overflow to navigate to my DerivedData folder, and then I manually deleted the subfolder for my project. After doing that, the project now builds successfully without the spurious warnings.

no Objective-C description available - Why?

I really have no idea why on this particular project my debugger is extremely 'disabled'.
For example I'll want to get info on an object:
(lldb) po [_model dictionaryValue]
[no Objective-C description available]
I'm wondering why this is. It's making debugging extremely difficult and it's only on this current project. I'm guessing I've done something to the settings at some point. It's on almost any po someObject I try to inspect. The variables in scope can be seen in the pane to the left of the debug console however.
I'm on Xcode 5, I have Cocoapods in my project, and it's a Unit Testing Target.
Any insights or any way to fix this?
Update:
For clarity, part of how the test case is implemented:
#interface WWCGateModelTests : XCTestCase
{
WWCGate *_model;
}
#end
#implementation WWCGateModelTests
- (void)setUp
{
[super setUp];
// Put setup code here; it will be run once, before each test case.
_model = [WWCGate loadGateModelWithIdentifier: kGateName]; // defined, not nil
}
- (void)tearDown
{
[super tearDown];
NSError *error = nil;
[_model saveModelOrError:&error];
// Breakpoint here. po _model does not print the model.
// This has been possible with other projects... po error will print
// nil to the console. How is an ivar not in scope?
}
This is likely happening because Unit Testing Targets typically are set up to run with "Release" configurations. "Release" configurations are ones where the debugging symbols have been stripped or optimized away.
I suspect you won't have this problem if you make certain you're running with a non-optimized, symbols-in-place Debug version of your app. You can change that in Xcode's scheme editor (e.g. when doing "Test" or "Profile", use the "Debug" configuration).
Are you sure you aren't using it on primitive types? Use p intVariable on those.
Every object will respond to description by at least printing class and memory address.
I've tracked down the issue (but haven't fixed it fully yet). It has to do with the Mantle Framework. In its description method it wants to spit out the contents of an NSDictionary that it generates at that point. There's something wrong with the way I set up my model I believe so creating this dictionary (based probably on how I configured some property) is basically failing.
I overrode the description method to return a standard description:
- (NSString*)description
{
return [NSString stringWithFormat:#"<%#: %p>", self.class, self];
}
and everything is fine and good again on planet Earth. ;-)
Thanks to those who were particularly patient. A more detailed discussion about this issue can be found at UPDATE 3 of the following post: http://horseshoe7.wordpress.com/2013/05/26/hands-on-with-the-mantle-model-framework/

Add google Plus api and youTube api in objective c at the same time

I am working on a project in which I have to add google plus and youtube api's for iOS. The issue I am facing is that it gives some duplication error while linking:
duplicate symbol _kCharsToForceEscape
and the files it show redundant are:
GDataUtilities.o and GTLUtilities.o
Any kind of help will be appreciated.
Thank you
I have had the same issue, and you can't delete Gdata utilities or GLT Utility because they are called in almost every case in GDATA and the GLT. there is a way around this go to gdata utilities and go down to the part where it says #pragma mark string encoding look for this line of code:
const CFStringRef kCharsToForceEscape = CFSTR("!*'();:#&=+$,/?%#[]");
comment this out.
Then comment this part out:
//CFStringRef escapedStr;
//escapedStr = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
// originalString,
// leaveUnescaped,
// kCharsToForceEscape,
// kCFStringEncodingUTF8);
// if (escapedStr) {
// resultStr = [(id)CFMakeCollectable(escapedStr) autorelease];
// }
If will be in there twice make sure you comment both out.
Then run app.
It worked for me I seem to have youtube working and it seems to compile the google plus API OK.

Get Path to selected file in Finder

How would I retrieve an array of paths to the selected files in Finder?
I have searched around but have only found links regarding AppleScript. I have also looked at NSWorkspace and NSFileManager but I didn't find anything.
Expanding on #Bavarious's (correct) answer, here's how I've gotten the selection from Finder using the Scripting Bridge:
#import "Finder.h" //my copy is here: https://github.com/davedelong/BetterInfo/blob/master/Finder.h
FinderApplication * finder = [SBApplication applicationWithBundleIdentifier:#"com.apple.finder"];
SBElementArray * selection = [[finder selection] get];
NSArray * items = [selection arrayByApplyingSelector:#selector(URL)];
for (NSString * item in items) {
NSURL * url = [NSURL URLWithString:item];
NSLog(#"selected item url: %#", url);
}
If it is possible to get the list of selected files in a given Finder window using AppleScript, you can probably use Scripting Bridge in a Cocoa application to interface with Finder. Quoting Apple’s documentation,
Scripting Bridge is a framework and a technology that makes it much easier for Cocoa developers to control and communicate with scriptable applications. Instead of incorporating AppleScript scripts in your application or dealing with the complexities of sending and handling Apple events, you can simply send Objective-C messages to an object that represents an application with a scripting interface. Your Cocoa application can do anything an AppleScript script can, but it does so in Objective-C code that is integrated with the rest of your project’s code.
There is no Cocoa class that represents Finder or, more specifically, Finder windows. Finder is an application, and a scriptable application at that, so Scripting Bridge is the way to go.