APAddressBook with Swift 3 - EXC_ARM_BREAKPOINT - ios

I am updating one of my apps to Swift 3 and i am using the APAddressBook Library (https://github.com/Alterplay/APAddressBook) as always. Here is a Swift example from APAddressBook but this fails, too
self.addressBook.loadContacts({ (contacts: [APContact]?, error: NSError?) in
if let uwrappedContacts = contacts {
// do something with contacts
}
else if let unwrappedError = error {
// show error
}
} as! APLoadContactsBlock)
The app crash with "Thread 1: EXC_BREAKPOINT (EXC_ARM_BREAKPOINT)" but i have no idea why.

this fix the problem , after add NSContactsUsageDescription in your info.plist
addressBook.loadContacts { (contacts: [APContact]?, error: Error?) in
if let unwrappedContacts = contacts {
//your code
}else if error != nil {
//your code for error
}
}

Firstly check if APAddressBook is supporting Swift 3. Then read carefully description of the framework.
Warning for iOS 10.0 and after
To protect user privacy, an iOS app linked on or after iOS 10.0, and
which accesses the user’s contacts, must statically declare the intent
to do so. Include the NSContactsUsageDescription key in your app’s
Info.plist file and provide a purpose string for this key. If your app
attempts to access the user’s contacts without a corresponding purpose
string, your app exits.

Related

Supporting Share Sheet Suggestions

Following this article I'm trying to implement share sheet suggestions in my messaging app.
I have declared INSendMessageIntent support in my Share extension's info.plist.
It's even showing up in the target under 'Supported Intents'.
But every time I'm donating a INSendMessageIntent it fails saying INSendMessageIntent is not supported.
Error Domain=IntentsErrorDomain Code=1901 "Donating intent 'INSendMessageIntent' is not supported by this extension. Please make sure that you declare the intents that your app supports by including the NSUserActivityTypes key in its Info.plist or your app contains an Intents extension that supports this intent."
// Create an INSendMessageIntent to donate an intent for a conversation with Juan Chavez.
let groupName = INSpeakableString(spokenPhrase: "Juan Chavez")
let sendMessageIntent = INSendMessageIntent(recipients: nil,
content: nil,
speakableGroupName: groupName,
conversationIdentifier: "sampleConversationIdentifier",
serviceName: nil,
sender: nil)
// Add the user's avatar to the intent.
let image = INImage(named: "Juan Chavez")
sendMessageIntent.setImage(image, forParameterNamed: \.speakableGroupName)
// Donate the intent.
let interaction = INInteraction(intent: sendMessageIntent, response: nil)
interaction.donate(completion: { error in
if error != nil {
// Add error handling here.
} else {
// Do something, e.g. send the content to a contact.
}
})
You should add NSUserActivityTypes entry to your app's Info.plist. Declare it as array and add your intents to it.

Authenticating the user with biometrics causing application to crash

So i'm following the books in terms of authenticating a user using biometrics. Below is some code i've wrote in a custom class called biometrics manager.
func authenticateUser(completion: #escaping (_ result: BiometricsStatus) -> Void) {
DispatchQueue.main.async {
guard self.deviceHasBiometricCapabilities() else { completion(.fail(error: .touchIDNotAvailable)); return }
let authMethod = self.biometricType() == .faceID ? "Face ID" : "Touch ID"
let loginMessage = "\(authMethod) to sign in"
self.context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: loginMessage) { success, evaluateError in
if success {
completion(.success)
return
}
if let error = evaluateError {
completion(.fail(error: self.getBiometricsError(from: error)))
return
}
}
}
}
I've debugged my application and it seems to be causing a crash on the evaluate policy line, i've enabled exception breakpoints to try and catch the crash but i'm receiving nothing at all in the console logs. The only thing that i seem to be getting in the console is the following.
Message from debugger: Terminated due to signal 9
Which isn't super helpful any possible pointers or ideas that may be causing this crash to occur at all?
You need to add the NSFaceIDUsageDescription key to your info.plist
From https://developer.apple.com/documentation/localauthentication/lacontext
Important
Include the NSFaceIDUsageDescription key in your app’s Info.plist file if your app allows biometric authentication. Otherwise, authorization requests may fail.

iOS IDFA (advertising identifier) is changing whenever relaunching app. Where is wrong in my swift code?

The following my code returns changed UUID string whenever I relaunch my app. Sometimes, it returns correct value (real IDFA) as "The Identifiers" iOS app is showing in "Advertising Identifier" field. It seems like round-robin??
I didn't reset the advertising identifier.
Anyone has the same experience?
import AdSupport
class IdManager {
static func getIDFA() -> String? {
if ASIdentifierManager.sharedManager().advertisingTrackingEnabled {
return ASIdentifierManager.sharedManager().advertisingIdentifier.UUIDString
}
return nil
}
}

Open URL from button action in Swift

In my app I am retrieving an URL from a parse.com Object.
I want to open the device's browser and show the URL received from Parse when the user clicks on the button.
This is the action:
#IBAction func botonNuevos(sender: AnyObject) {
let query = PFQuery(className: "datos_contacto")
query.getObjectInBackgroundWithId("H52ZxGm3U8", block: {
(questionObject: PFObject?, error: NSError?) -> Void in
let webNuevos: AnyObject! = questionObject!.valueForKey("dato_contacto")
print(webNuevos) //= http://www.touchemotors.com
if let webCallURL = NSURL(string: webNuevos as! String ) {
let application = UIApplication.sharedApplication()
if application.canOpenURL(webCallURL) {
application.openURL(webCallURL)
}
else{
print("failed")
}
}
})
}
when the button is clicked, the log shows the received URL, but the browser is not launched and any error is shown.
Please tell what is wrong in my code. Thank you
UPDATE
Finally after discussion with OP it turned out that value returned by questionObject!.objectForKey("dato_contacto") had whitespace at the end so NSUrl(string:) did not parse it well.
UPDATE
You are using wrong method NSObject.valueForKey(). Use PFObject.objectForKey() instead.
For iOS 9:
From here:
If your app is linked on or after iOS 9.0, you must declare the URL
schemes you want to pass to this method. Do this by using the
LSApplicationQueriesSchemes array in your Xcode project’s Info.plist
file. For each URL scheme you want your app to use with this method,
add it as a string in this array.
If your (iOS 9.0 or later) app calls this method using a scheme you
have not declared, the method returns false, whether or not an
appropriate app for the scheme is installed on the device.
Add http scheme to LSApplicationQueriesSchemes array in Info.plist.

'openParentApplication(_:reply:)' has been explicitly marked unavailable here - Xcode 7 Beta

After updating to Xcode 7 beta, I receive the following error message: "'openParentApplication(_:reply:)' has been explicitly marked unavailable here", when running the line of code "WKInterfaceController.openParentApplication"
Here is my actual code:
func getData(messageText: String) {
let infoDictionary = ["message" : messageText]
WKInterfaceController.openParentApplication(infoDictionary) {
(replyDictionary, error) -> Void in
if let castedResponseDictionary = replyDictionary as? [String: String],
responseMessage = castedResponseDictionary["message"]
{
print(responseMessage)
}
}
}
+[WKInterfaceController openParentApplication:] is only relevant for WatchKit1 app extensions because with WatchKit1 app extensions, the appex is running on the phone instead of on the watch.
With WatchKit2 app extensions, the appex is running on the watch, so actions such as this are less trivial to accomplish. You probably want to use -[WCSession sendMessageData:replyHandler:errorHandler:] from WatchConnectivity.framework for what you're doing.

Resources