I am working on an existing objective c project , While reading Address Book UI Framework Reference for iOS i found the below classes have deprecated in iOS 9 .
( ABUnknownPersonViewController , ABPersonViewController , ABPeoplePickerNavigationController, ABNewPersonViewController )
What is the replacement of this .? Where i can find some document related this . any help appreciated . Thanks in advance .
The AddressBookUI framework has been deprecated in iOS 9, so better you should use ContactsUI Framework.
It has many new features including all the features of AddressBookUI framework.
So, in case if you are targeting the iOS 9 specifically then you should go for ContactsUI Framework.
To check that AddressBookUI framework is available for specific iOS version you can do the following:
if ([CNContactStore class]) {
CNContactStore *store = [CNContactStore new];
//...
} else {
// Fallback to old framework
}
Here is the complete code for that:
- (void) contactScan
{
if ([CNContactStore class]) {
//ios9 or later
CNEntityType entityType = CNEntityTypeContacts;
if( [CNContactStore authorizationStatusForEntityType:entityType] == CNAuthorizationStatusNotDetermined)
{
CNContactStore * contactStore = [[CNContactStore alloc] init];
[contactStore requestAccessForEntityType:entityType completionHandler:^(BOOL granted, NSError * _Nullable error) {
if(granted){
[self getAllContact];
}
}];
}
else if( [CNContactStore authorizationStatusForEntityType:entityType]== CNAuthorizationStatusAuthorized)
{
[self getAllContact];
}
}
}
-(void)getAllContact
{
if([CNContactStore class])
{
//iOS 9 or later
NSError* contactError;
CNContactStore* addressBook = [[CNContactStore alloc]init];
[addressBook containersMatchingPredicate:[CNContainer predicateForContainersWithIdentifiers: #[addressBook.defaultContainerIdentifier]] error:&contactError];
NSArray * keysToFetch =#[CNContactEmailAddressesKey, CNContactPhoneNumbersKey, CNContactFamilyNameKey, CNContactGivenNameKey, CNContactPostalAddressesKey];
CNContactFetchRequest * request = [[CNContactFetchRequest alloc]initWithKeysToFetch:keysToFetch];
BOOL success = [addressBook enumerateContactsWithFetchRequest:request error:&contactError usingBlock:^(CNContact * __nonnull contact, BOOL * __nonnull stop){
[self parseContactWithContact:contact];
}];
}
}
- (void)parseContactWithContact :(CNContact* )contact
{
NSString * firstName = contact.givenName;
NSString * lastName = contact.familyName;
NSString * phone = [[contact.phoneNumbers valueForKey:#"value"] valueForKey:#"digits"];
NSStrubg * email = [contact.emailAddresses valueForKey:#"value"];
NSArray * addrArr = [self parseAddressWithContac:contact];
}
- (NSMutableArray *)parseAddressWithContac: (CNContact *)contact
{
NSMutableArray * addrArr = [[NSMutableArray alloc]init];
CNPostalAddressFormatter * formatter = [[CNPostalAddressFormatter alloc]init];
NSArray * addresses = (NSArray*)[contact.postalAddresses valueForKey:#"value"];
if (addresses.count > 0) {
for (CNPostalAddress* address in addresses) {
[addrArr addObject:[formatter stringFromPostalAddress:address]];
}
}
return addrArr;
}
Just make sure that you ask the permission to read the contacts from device.
Reference link: https://gist.github.com/willthink/024f1394474e70904728
Updated:
For replacement for AddressBookUI you need to use CNContactPickerViewController. You can check the delegate methods which can be used to pickup the one or multiple contacts at a time.
This will present a inbuilt UIViewController with all the contacts and you need to implement the delegate methods of it!
To select one contact:
contactPicker:didSelectContact:
To select multiple (New Feature):
contactPicker:didSelectContacts:
CNContactPickerDelegate reference: https://developer.apple.com/library/ios/documentation/ContactsUI/Reference/CNContactPickerDelegate_Protocol/
Apple has introduced new framework for this for iOS9 and above please fine below link Link
Edit:
one more link :Link2
Related
I am trying to integrate Hyperpay payment into React Native project and I have problems with objective-c, I followed an article and found many issues and with searching, I solve them, but still two issues I can't solve because I am not familiar with objective-c
Issue 1,
No known class method for selector 'presentCheckoutForSubmittingTransactionCompletionHandler:cancelHandler:'
Issue 2,
No known class method for selector 'dismissCheckoutAnimated:completion:'
I am sorry if my code is long but I don't to miss something
// RCTCalendarModule.m
#import "HyperPay.h"
#import "UIKit/UIKit.h"
#import <OPPWAMobile/OPPWAMobile.h>
#implementation HyperPay{
RCTResponseSenderBlock onDoneClick;
RCTResponseSenderBlock onCancelClick;
UIViewController *rootViewController;
NSString *isRedirect;
OPPPaymentProvider *provider;
}
// To export a module named RCTCalendarModule
RCT_EXPORT_METHOD(openHyperPay:(NSDictionary *)indic createDialog:(RCTResponseSenderBlock)doneCallback createDialog:(RCTResponseSenderBlock)cancelCallback) {
onDoneClick = doneCallback;
onCancelClick = cancelCallback;
NSArray *events = #[];
if ([indic[#"is_sandbox"] isEqualToString:#"1"]) {
provider = [OPPPaymentProvider paymentProviderWithMode:OPPProviderModeTest];
} else {
provider = [OPPPaymentProvider paymentProviderWithMode:OPPProviderModeLive];
}
OPPCheckoutSettings *checkoutSettings = [[OPPCheckoutSettings alloc] init];
// Set available payment brands for your shop
checkoutSettings.paymentBrands = #[#"VISA", #"MASTER"];
// Set shopper result URL
checkoutSettings.shopperResultURL = #"com.simicart.enterprise.payments://result";
OPPCheckoutProvider *checkoutProvider = [OPPCheckoutProvider checkoutProviderWithPaymentProvider:provider checkoutID:indic[#"checkoutId"]
settings:checkoutSettings];
dispatch_async(dispatch_get_main_queue(), ^{
[OPPCheckoutProvider presentCheckoutForSubmittingTransactionCompletionHandler:^(OPPTransaction * _Nullable transaction, NSError * _Nullable error) {
if (error) {
// Executed in case of failure of the transaction for any reason
if (isRedirect && ![isRedirect isEqualToString:#"1"]) {
onCancelClick(#[#"cancel", events]);
}
} else if (transaction.type == OPPTransactionTypeSynchronous) {
// Send request to your server to obtain the status of the synchronous transaction
// You can use transaction.resourcePath or just checkout id to do it
NSDictionary *responeDic = #{#"resourcePath" : transaction.resourcePath};
onDoneClick(#[responeDic, events]);
NSLog(#"%#", transaction.resourcePath);
} else {
// The SDK opens transaction.redirectUrl in a browser
// See 'Asynchronous Payments' guide for more details
}
} cancelHandler:^{
onCancelClick(#[#"cancel", events]);
// Executed if the shopper closes the payment page prematurely
}];
});
}
- (instancetype)init{
self = [super init];
if (self) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(getStatusOder:) name:#"getStatusOrder" object:nil];
}
return self;
}
- (void)getStatusOder:(NSNotification*)noti{
[OPPCheckoutProvider dismissCheckoutAnimated:YES completion:^{
isRedirect = #"1";
NSURL *url = noti.object;
NSString *urlString = [url absoluteString];
NSLog(#"%#", urlString);
if (![urlString isEqualToString:#"com.simicart.enterprise.payments://result"]) {
NSArray *events = #[];
NSDictionary *responeDic = #{#"url" : urlString};
onDoneClick(#[responeDic, events]);
}
}];
}
#end
I'm working on voip app. fetch contact work but when I want to make call, app crash.
[ABSAddressBook contacts]: message sent to deallocated instance
0x1c1478180 warning: could not execute support code to read
Objective-C class data in the process. This may reduce the quality of
type information available.
crash happen in this line.
NSArray *lContacts = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
- (void) checkContactListForJogvoiceList {
// if (![BundleLocalData isLoadingJogvoiceContactList]) {
// [BundleLocalData setLoadingJogvoiceContactList:true];
int maxPhoneNumberSubmit = 200;
NSArray *lContacts = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
NSMutableDictionary *phoneNumberContactsDictionary = [[NSMutableDictionary alloc] init];
NSMutableArray *allPhoneNumberList = [[NSMutableArray alloc] init];
for (id lPerson in lContacts) {
ABRecordRef person = (ABRecordRef)lPerson;
NSArray *phoneList = [AppUtil getContactPhoneList:person];
for (NSString* phoneNumber in phoneList) {
NSMutableArray* contactList = phoneNumberContactsDictionary[phoneNumber];
if (!contactList) {
contactList = [[NSMutableArray alloc] init];
}
[contactList addObject:(__bridge ABRecordRef)person];
phoneNumberContactsDictionary[phoneNumber] = contactList;
}
[allPhoneNumberList addObjectsFromArray:phoneList];
if (allPhoneNumberList.count >= maxPhoneNumberSubmit) {
[self checkContactList:allPhoneNumberList phoneNumberContactsDictionary:phoneNumberContactsDictionary];
}
}
if (allPhoneNumberList.count > 0) {
[self checkContactList:allPhoneNumberList phoneNumberContactsDictionary:phoneNumberContactsDictionary];
}
// ABAddressBookUnregisterExternalChangeCallback(addressBook, sync_address_book, self);
// [BundleLocalData setLoadingJogvoiceContactList:false];
// }
}
probably because AddressBook framework deprecate in ios9? am I right?
I don’t want to use Contacts framework.
According to Apple doc ABAddressBookCreateWithOptions using address book function ABAddressBookCreateWithOptions returns NULL if no permission granted from user.
On iOS 6.0 and later, if the caller does not have access to the Address Book database:
For apps linked against iOS 6.0 and later, this function returns NULL.
For apps linked against previous version of iOS, this function returns an empty read-only database.
You should follow this article How do I correctly use ABAddressBookCreateWithOptions method in iOS 6?
I am using QuickBlox SDK from follwing refrence
https://quickblox.com/developers/SimpleSample-chat_users-ios
In Sample chat I am also making Group video chat . but When I Update particular tag With the help of below code. Than I am unable to see the updated value in my quickblox admin panel. If some one update the tag name than Please suggest me. I am using below code
QBUUser *qbUser = [QBUUser user];
qbUser.ID = 23429378;
NSString *roomName = #"ios group";
qbUser.tags = #[roomName].mutableCopy;
NSArray *arry = [[NSArray alloc]initWithObjects:qbUser, nil];
[QMUsersCache.instance insertOrUpdateUsers:users];
- (BFTask *)insertOrUpdateUsers:(NSArray *)users
{
__weak __typeof(self)weakSelf = self;
return [BFTask taskFromExecutor:[BFExecutor executorWithDispatchQueue:self.queue] withBlock:^id{
__typeof(self) strongSelf = weakSelf;
NSManagedObjectContext* context = [strongSelf backgroundContext];
NSMutableArray *toInsert = [NSMutableArray array];
NSMutableArray *toUpdate = [NSMutableArray array];
//To Insert / Update
for (QBUUser *user in users)
{
CDUser *cachedUser = [CDUser QM_findFirstWithPredicate:IS(#"id", #(user.ID)) inContext:context];
if (cachedUser) {
QBUUser *qbCachedUser = [cachedUser toQBUUser];
if (![user.updatedAt isEqualToDate:qbCachedUser.updatedAt]) {
[toUpdate addObject:user];
}
}
else {
[toInsert addObject:user];
}
}
if (toUpdate.count > 0) {
[strongSelf updateUsers:toUpdate inContext:context];
}
if (toInsert.count > 0) {
[strongSelf insertUsers:toInsert inContext:context];
}
if (toInsert.count + toUpdate.count > 0) {
[context QM_saveToPersistentStoreAndWait];
}
QMSLog(#"[%#] Users to insert %tu, update %tu", NSStringFromClass([weakSelf class]), toInsert.count, toUpdate.count);
return nil;
}];
}
Your code is just updating users in CoreData store.
You can update only the current user from the application:
+ (QBRequest *)updateCurrentUser:(QBUpdateUserParameters *)parameters
successBlock:(nullable void (^)(QBResponse *response, QBUUser * _Nullable user))successBlock
errorBlock:(nullable QBRequestErrorBlock)errorBlock;
If you want to update other users you should do it via Admin Panel.
Sample chat related to this question.
API Documentation related to this question.
I have added extension to app(as per apple documentation) but intent handler class is not responding with my commands. what i am missing don't no.Please help me ,How can i add siri to my app.
// reslove
- (void)resolveContactsForStartAudioCall:(INStartAudioCallIntent *)intent
withCompletion:(void (^)(NSArray<INPersonResolutionResult *> *resolutionResults))completion{
NSArray *contacts;
NSArray * contacts1;
INPersonResolutionResult* result = nil;
if (contacts == intent.contacts) {
for (INPerson *contact in contacts) {
contacts1 = [self contactsMatchingName:contact.displayName];
switch (contacts1.count) {
case 1:
result = [contacts objectAtIndex:0];
[INPersonResolutionResult successWithResolvedPerson:[contacts1 objectAtIndex:0]];
break;
case 0:
result = [INPersonResolutionResult unsupported];
break;
default:
result = [ INPersonResolutionResult disambiguationWithPeopleToDisambiguate:contacts1];
break;
}
}
completion(contacts1);
}else{
result = [INPersonResolutionResult needsValue];
}
}
// confirmation method
- (void)confirmStartAudioCall:(INStartAudioCallIntent *)intent
completion:(void (^)(INStartAudioCallIntentResponse *response))completion{
INStartAudioCallIntentResponse *result = nil;
if (![[NSUserDefaults standardUserDefaults]objectForKey:#"isSignedIn"]) {
result = [[INStartAudioCallIntentResponse alloc]initWithCode:INStartAudioCallIntentResponseCodeReady userActivity:nil];
completion(result);
}else{
NSUserActivity *activity = [[NSUserActivity alloc]initWithActivityType:#"reLogin"];
result = [[INStartAudioCallIntentResponse alloc]initWithCode:INStartAudioCallIntentResponseCodeFailure userActivity:activity];
completion(result);
}
}
Here are a few resources to get you started.
Guides and Documentation
SiriKit Programming Guide
Intents Framework
IntentsUI Framework
Sample Code
UnicornChat Sample App
Videos (from WWDC 2016)
Introducing SiriKit
Extending your app with SiriKit
During researching of the PrivateFrameworks that are available at iOS 9 i found interesting library that could give access to the call history of the jailbreak iPhone. The question is how to use this framework?
Brief example of my :
NSBundle *b = [NSBundle bundleWithPath:#"/System/Library/PrivateFrameworks/CallHistory.framework"];
BOOL success = [b load];
if (success) {
Class CallHistoryDBHandle = NSClassFromString(#"CallHistoryDBClientHandle");
SEL theSelector = NSSelectorFromString(#"fetchAllNoLimit");
id si = [CallHistoryDBHandle valueForKey:#"createForClient"];
NSLog(#"-- %#", [si performSelector:theSelector]);
} else {
NSLog(#"NO");
}