How to import contacts into my app - ios

I need to access the contacts of my iPhone into my app.
I am using Xcode 7.2 and IOS-9.
Give me best framework or library which is usefully for me.
I try to work on the ABAddressbook framework but it has been deprecated.
Thank You.

Apple has introduced new frameworks Contacts and ContactsUI for accessing contacts for iOS9 and above.
The previous ABAddressbook framework has been deprecated. You might find a lot of info in SO on this.
You can make use of ContactsUI framework for iOS9+ devices
- (void) presentContacts
{
CNContactPickerViewController *contactPicker = [[CNContactPickerViewController alloc] init];
contactPicker.delegate = self;
[_myViewController presentViewController:contactPicker animated:YES completion:nil];
}
//Listen for delegates
- (void) contactPickerDidCancel: (CNContactPickerViewController *) picker
{
NSLog(#"didCancel");
}
- (void) contactPicker: (CNContactPickerViewController *) picker
didSelectContact: (CNContact *) contact
{
NSLog(#"didSelectContact"):
}
- (void) contactPicker: (CNContactPickerViewController *) picker
didSelectContactProperty: (CNContactProperty *) contactProperty
{
NSLog(#"didSelectProperty");
}

CNContactPickerViewController
https://developer.apple.com/library/ios/documentation/ContactsUI/Reference/CNContactPickerViewController_Class/
Address book ui framework
https://developer.apple.com/library/ios/documentation/AddressBookUI/Reference/AddressBookUI_Framework/index.html
MFMessageComposeViewController https://developer.apple.com/library/ios/documentation/MessageUI/Reference/MFMessageComposeViewController_class/
tutorials http://www.appcoda.com/ios-programming-import-contact-address-book/
http://gabriel-tips.blogspot.in/2012/02/how-to-import-contacts-from-address.html

Related

Implementing Voice navigation in HERE maps

I am building a map-based app in iOS (Objective-C) using HERE maps, and am new to this. I was successful in implementing navigation but I am facing a hitch in implementing voice instruction for navigation. This is the code that I have:
- (void) beginNavigationMethod {
self.mapView.zoomLevel = 17.0;
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(didUpdatePositionForNavigation) name:NMAPositioningManagerDidUpdatePositionNotification object:[NMAPositioningManager sharedPositioningManager]];
NMAVoiceCatalog *voiceCatalog = [NMAVoiceCatalog sharedVoiceCatalog];
voiceCatalog.delegate = self;
[voiceCatalog updateVoiceCatalog];
[self.navigationManager startTurnByTurnNavigationWithRoute:self.route];
[NMANavigationManager sharedNavigationManager].mapTrackingEnabled = YES;
[NMANavigationManager sharedNavigationManager].mapTrackingAutoZoomEnabled = YES;
[NMANavigationManager sharedNavigationManager].mapTrackingOrientation
= NMAMapTrackingOrientationDynamic;
[NMANavigationManager sharedNavigationManager].speedWarningEnabled = YES;
NSError* error = [[NMANavigationManager sharedNavigationManager] startTurnByTurnNavigationWithRoute:self.route];
NSLog(#"%#",error);
}
- (void)voiceCatalog:(nonnull NMAVoiceCatalog *)voiceCatalog didUpdateWithError:(nullable NSError *)error {
NSLog(#"didUpdateWithError: %#",error);
}
I basically don't know how to proceed with this. My apologies for being so naive. If anyone could guide me through this, it would be a great help.
You can look at docs: https://developer.here.com/documentation/ios-premium/topics/map-voice-instructions.html
Otherwise, where is an example for Android: https://github.com/heremaps/here-android-sdk-examples/issues/36#issuecomment-304873154, if you can go through it it will give you an impression of how to do that.
Please try this code
[[NMANavigationManager sharedNavigationManager] setVoicePackageMeasurementSystem:NMAMeasurementSystemImperialUS];
[[NMAAudioManager sharedAudioManager] setDelegate:self];
[[NMAAudioManager sharedAudioManager]setManagesAudioSession:NO];
Here Map Delegate Method
- (BOOL)audioManager:(NMAAudioManager *)audioManager shouldPlayOutput:(NMAAudioOutput *)output{
return true;
}
Project Setting->General->Capabilities->Background Modes

CNContactPickerViewController remove searchbar (Objective c)

//import contacts by using contact picker
CNContactPickerViewController *contactPicker = [CNContactPickerViewController new];
contactPicker.delegate = self;
NSPredicate *filterPredicate = [NSPredicate predicateWithFormat:#"phoneNumbers.#count >= 1"];
contactPicker.predicateForEnablingContact = filterPredicate;
[self presentViewController:contactPicker animated:YES completion:nil];
- (void) contactPicker:(CNContactPickerViewController *)picker
didSelectContacts:(NSArray<CNContact *> *)contacts {
//code for selecting multiple contacts
}
-(void)contactPickerDidCancel:(CNContactPickerViewController *)picker {
NSLog(#"Cancell");
}
I am using the above code to import the contacts, i am able to import the contacts. But i need to remove the searchbar from the CNContactPickerViewController. I have already tried the below solution provided in the stack overflow but its not working. Any help will be really appreciated.
How to hide/Remove the search bar on Contact Picker
As the CNContactPickerViewController is a UIRemoteView you have no access to it. As such this is not possible.

Application tried to present inside popover with transition style other than UIModalTransitionStyleCoverVertical before printing

I am trying to print a txt file from within a iPad 8.x application. So, I have this code:
- (void)onOpenWith:(UIButton *)theButton path:(NSString *)path
{
NSURL *URL = [NSURL fileURLWithPath:path];
if (URL) {
self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:URL];
self.documentInteractionController.delegate = self;
[self.documentInteractionController presentPreviewAnimated:YES];
}
}
#pragma mark - UIDocumentInteractionControllerDelegate
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller
{
return self;
}
- (UIView *)documentInteractionControllerViewForPreview:(UIDocumentInteractionController *)controller
{
return self.view;
}
- (CGRect)documentInteractionControllerRectForPreview:(UIDocumentInteractionController *)controller
{
return self.view.frame;
}
Now everything is going as expected, I see a preview of the file, then I touch the icon on the top right corner of the screen and I am able to share the document in those applications that can handle it. However, if I touch PRINT I get this error message:
Application tried to present inside popover with transition style
other than UIModalTransitionStyleCoverVertical
and the app crashes. Sure, i understand it, but to which viewcontroller should I apply this transition? I have no control on the popover showing the print dialog...
In iOS 7 (real iPad not simulator) everything works...
Can anybody help me?
Thanks
Fabio
I also came across this issue, and the solution was that I had to build and run my app with Xcode 6 installed.
On my older machine, I have Xcode 5.1.1, and when run from there, this same issue appeared, and some more issues from this view (like cannot dismiss mail controller when opened from the top right corner).

iOS 7 and the MPMediaPicker, why plus?

I've got two strange diverging behaviours between iOS 6 and 7.
I want to present the MPMediaPicker to the end user, allow them to select 1 song, and start playing that back to them.
So, I show them the MPMediaPicker (/not/ multi, and /not/ cloud, if supported).
Two problems:
In iOS6, the first screen in MPMediaPicker shows the songs. In iOS7,
it's the (empty) playlists. How can I force the MPMediaPicker to
show songs as the default first screen? Is this just another example of Apple "knowing best"?
In iOS7 I get a red (+) symbol next to the media items in the list. What
causes that? I haven't been able to turn up any references for that
in google. What is the (+) symbol? It doesn't seem to highlight separately from the line in the table. The native media picker doesn't display this.
Thanks!
-Ken
Our MPMediaPicker code:
- (void)showSongPicker {
// TODO check if iOS 6
MPMediaPickerController* songPicker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeMusic];
songPicker.delegate = self;
songPicker.allowsPickingMultipleItems = NO;
songPicker.showsCloudItems = NO;
[self presentViewController:songPicker animated:YES completion:nil];
[self presentModalViewController:songPicker animated:YES];
}
#pragma mark MPMediaPickerControllerDelegate
- (void)mediaPicker: (MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection {
MPMediaItem* item = [mediaItemCollection.items objectAtIndex:0];
[self playMediaItem:item];
[self mediaPickerDidCancel:mediaPicker];
}
- (void)mediaPickerDidCancel:(MPMediaPickerController *)mediaPicker {
[self dismissViewControllerAnimated:YES completion:nil];
}
Oh! I do apologise. I'd forgotten to answer this.
Since I didn't get an answer from anyone else (until just now, thanks, lap.felix), I filed it as a technical question with Apple.
Their answer?
There's no programmatic way to affect the behaviour of the picker. If you need to change the behaviour this "drastically", you have to roll your own media picker.
So...yeah...thanks, Apple.
-Ken
The + doesn't mean anything other than "Add this item to the picker selection"

ShareKit lose focus when actionsheet is closed

I´m trying to integrate ShareKit in my ios game.
Everything is working fine and the actionsheet is shown and I can interact with it but I´m not able to return the focus to my app when the sharekit action has finished (by closing the actionsheet or finishing any action).
I have tried in several ways but any has worked for me. What´s happening?
I´m not an expert programmer so I expect I´m missing something.
I´m
This is my .h
#import <UIKit/UIKit.h>
#import "SHK.h"
#import "SHKConfiguration.h"
#interface SocialWrapper: UIViewController{
}
- (id) init;
- (void) open;
- (void) dealloc;
#end
and .m
#import "SocializeWrapper.h"
#implementation SocialWrapper
- (id) init {
self=[super init];
DefaultSHKConfigurator *configurator = [[DefaultSHKConfigurator alloc] init];
[SHKConfiguration sharedInstanceWithConfigurator:configurator];
[SHK flushOfflineQueue];
return self;
}
- (void) open
{
NSString *someText = #"Hello Earth!";
SHKItem *item = [SHKItem text:someText];
// Get the ShareKit action sheet
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
UIWindow *window = [UIApplication sharedApplication].keyWindow;
[window addSubview:self.view];
[SHK setRootViewController:self];
[actionSheet showInView:self.view];
}
- (void) dealloc {
NSLog(#"SHK dealloc");
[self release];
[super dealloc];
}
#end
I´m calling it by using this wrapper
#import "SocializeWrapper.h"
SocialWrapper *socialize;
void SHKinit(void) {
NSLog(#"SHK Init");
socialize = [[SocialWrapper alloc] init];
}
void SHKopenWeb(void){
NSLog(#"SHK Open actionsheet");
[socialize open];
}
I´m working with ios 5, xcode 4.3.2 and the last sharekit version from the git.
I think I have to dissmiss my SocialWrapper once the actionsheet is closed but I don´t know how to capture that event, or even if this is correct. I´m stucked.
any help will be greatly appreciated.
UPDATE
As comment adviced, now the controller is on a category, using the actionsheet delegate, the focus can be regained when clicking the cancel´s actionsheet button. The problem still persists when an action is finished or cancelled. Don´t know how to capture that event.
This is my category code:
#import "SocialWrapper.h"
#implementation UIViewController (SocialController)
-(void) loadconfig
{
DefaultSHKConfigurator *configurator = [[DefaultSHKConfigurator alloc] init];
[SHKConfiguration sharedInstanceWithConfigurator:configurator];
[SHK flushOfflineQueue];
}
- (void) open
{
NSLog(#"Opening social button");
NSString *someText = #"Monkey Armada rules!";
SHKItem *item = [SHKItem text:someText];
// Get the ShareKit action sheet
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
UIWindow *window = [UIApplication sharedApplication].keyWindow;
[window addSubview:self.view];
[actionSheet setDelegate:self];
[SHK setRootViewController:self];
[actionSheet showInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSLog(#"SHK actionsheet dissmiss with button %d", buttonIndex);
if(buttonIndex == 4)
{
NSLog(#"SHK close actionsheet");
[self dismissViewControllerAnimated:YES completion:nil];
[self.view removeFromSuperview];
}
}
#end
Well since SHKActionSheet is a subclass of UIActionSheet you can set the delegate of that class to self to know when the dismissal happens.
Also, [self release]; in dealloc is complete misunderstanding of what release does, if you're in dealloc then releasing self won't do anything !
Learn the memory management rules.
I should also warn you that [window addSubview:self.view] is deprecated, you should not do that at all. In fact, I don't see a reason to wrap share kit stuff each view controller should be able to write that code easily. At worse you could put that code in a category on UIViewController if you don't want to rewrite the code every time.

Resources