I'm new at Swift 3 and I try to make a print("Test") in a Widget extension.
I tried the same code in ViewController.swift and It works ok. I don't know why it works there but it doesn't on TodayViewController.swift. I can't access to objects too.
func loadData() {
let query = PFQuery(className: "Noticias")
query.whereKey("titulo", equalTo:"Es Navidad")
query.findObjectsInBackground(block: { (objects : [PFObject]?, error: Error?) -> Void in
if error == nil {
// The find succeeded.
print("Successfully retrieved \(objects!.count) scores.")
// Do something with the found objects
if let objects = objects {
for object in objects {
print(object.objectId!)
}
}
} else {
// Log details of the failure
print("bad day homie")
print(error!)
}
})
}
I attach I picture to see it clearly. If I try to print on the file marked as Work, it works. But if I try it on the file marked ad NO, it doesn't.
It is extremely difficult to retrieve print messages from an extension. The problem is that it's an extension! It isn't running in your app, so it doesn't arrive at your console. Sometimes I find you can solve this problem by switching the debugged process in the Debug Bar at the top of the debug area (at the bottom of the screen, not shown in your screen shot), but at other times this doesn't work.
I'll illustrate a possible technique that seems to be pretty reliable. Look at this screen shot:
"Expand" is an action extension. But my containing app is called "bk2ch13...". So how will I ever manage to pause at the breakpoint shown at the right, which is in the action extension? This is what I do.
First, with the screen as shown above, I build and run my containing app.
Then, I switch the target to the action extension:
Now I build and run again. But now I am trying to run an action extension, which you can't do, so Xcode asks me what app to run:
So I choose "bk2ch13...". So now we are running my host app again, but we are debugging the extension. So I use my host app to exercise the extension, and sure enough, we pause at the breakpoints and print statements arrive into the console.
Note, in that screen shot, how the debug bar clearly shows that we are talking to the extension, not the host app.
Related
I'm creating snapshots using Fastlane. As my application uses "Push Notifications", when the app is launched it always displays to the user the pop up that requests the authorization to send this kind of messages. There is a method that is called in the AppDelegate UIApplication.shared.registerForRemoteNotifications(), this method is the one that "shows" the pop up to the user.
I have tried something like:
#if !DEBUG
UIApplication.shared.registerForRemoteNotifications()
#endif
#if TARGET_IPHONE_SIMULATOR
UIApplication.shared.registerForRemoteNotifications()
#endif
I also tried to set a Global variable but it hasn't been possible to find a place where to set this variable, because it never works
I always get the same behavior.
I would expect that the first time I run the test in the simulator, it does not display the message.
Thanks.
I found an easy way to avoid this screenshot.
Before the screenshot is taken, I simply press the button "Allow"
let systemAlerts = XCUIApplication(bundleIdentifier: "com.apple.springboard").alerts
if systemAlerts.buttons["Allow"].exists {
systemAlerts.buttons["Allow"].tap()
}
Simple an easy :)
Looking at the flutter code it seems like I should be able to run the google places modal dialog since it does a full screen thing and doesn't try and overlay on top of flutter.
However I am having an issue where the modal shows up and then disappears again immediately. I am not entirely sure how to solve this...
I am activating it with:
call.method == "openPlacesDialogModal" -> {
val code = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(activity)
if (GoogleApiAvailability.getInstance().showErrorDialogFragment(activity, code, REQUEST_GOOGLE_PLAY_SERVICES)) {
return
}
//val intent = Intent(activity, PlacesActivity::class.java)
//activity.startActivity(intent)
var intentBuilder = PlacePicker.IntentBuilder()
activity.startActivityForResult(intentBuilder.build(activity), PLACE_PICKER_REQUEST)
placeResult = result
return
}
In the logs I get:
I/FlutterActivityDelegate(18184): onResume setting current activity to this
I/flutter (18184): Opening picker
I/FlutterActivityDelegate(18184): onResume setting current activity to this
I think it is the onResume getting back to the ActivityDelegate that is the issue.
I put this on top of a completely different activity too, which kind of works. It shows the dialog for longer. I made sure I have all the right permissions, I have the fine location, internet permissions. Do I need to setup anything else?
Thanks,
David.
Error here was that I was not setting up the google api correctly and it was erroring immediately. Had to put in some checks to look for this error so I could respond correctly to the app that an error occurred.
I am using XCode Version 9.0 beta (9M136h) to write an application with a watchkit extension. I can get the application to communicate with the watch app and send information back and forth using the WatchConnectivity Framework. I also have the app utilizing the AlamoFire framework to communicate with a server.
All my functions are being called and executing, however, i cant seem to get print() to log anything to the console! I have tried placing various print() commands in different areas of the application, but none of them are producing anything to the console, even though the code around them is working.
I am 100% sure that I am looking at the correct area of XCode, I have gone to View->Debug Area->Activate Console and I have also made sure that All output is selected. I even tried adding the OS_ACTIVITY_MODE with its value as disabled but that didn't seem to do anything, either.
Here is an example of how I am using it in my ViewController.swift file:
override func viewDidLoad()
{
super.viewDidLoad()
print("view did load")
initWCSession()
print("Attorney General Jeff Sessions")
}
This code runs and calls the initWCSession() function but I never see any output of "view did load" or "Attorney General Jeff Sessions" anywhere!
Is this is a bug in XCode? Is there something I am forgetting? (I am new to XCode).
Try view.backgroundColor = .red
I think view contoller is not being called. Just a guess. Otherwise printshould work.
I am not sure why this worked but I went into Edit Scheme and checked the checkboxes for logging malloc. I saved these settings and then went back into Edit Scheme and unchecked the boxes and saved.
After that, I started seeing the print() statements log to the console!
Must be a bug in this version of XCode.
On the recent Xcode 11.3.1 I was getting the log lines from CocoaLumberjack, but nothing from my print calls. Restarting Xcode fixed the problem.
Starting with a blank OS X application project, I add the following code to applicationDidFinishLaunching.
func applicationDidFinishLaunching(aNotification: NSNotification) {
let app = NSApplication.sharedApplication()
guard let window = app.keyWindow else {
fatalError("No keyWindow\n")
}
print(window)
}
At launch I hit the error case because my local window variable is nil. Yet when I show the contents of the app variable, I see a valid value for _keyWindow. Also notice that the blank GUI Window is being displayed on the screen next to the stack dump.
Why does the keyWindow: NSWindow? property return nil in this case?
Thanks
NSApplication's keyWindow property will be nil whenever the app is not active, since no window is focused for keyboard events. You can't rely on it being active when it finished launching because the user may have activated some other app between when they launched your and when it finished launching, and Cocoa is designed to not steal focus.
To some extent, you may be seeing that happen more when launching from Xcode because app activation is a bit strange in that case. But, still, you must not write your applicationDidFinishLaunching() method to assume that your app is active.
What you're seeing in terms of the app's _keyWindow instance variable is, of course, an implementation detail. One can't be certain about what it signifies and you definitely should not rely on it. However, I believe it's basically the app's "latent" key window. It's the window that will be made key again when the app is activated (unless it is activated by clicking on another of its windows).
I'm just getting into Swift and I'm stumbling over this one. I want to get the contact image of a contact in the method
func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController!, didSelectPerson person: ABRecord!, property: ABPropertyID, identifier: ABMultiValueIdentifier)
I first check if the contact has an image and then copy that into a newly created constant with
if(ABPersonHasImageData(person))
{
let avatar : NSData = ABPersonCopyImageDataWithFormat(person, kABPersonImageFormatThumbnail).takeRetainedValue()
}
problem is, it always returns false in the simulator. Couldn't yet try it on my real phone.
What am I doing wrong? There are no errors. Extracting all other information from the contact works just fine.
Fixed it myself just now. After trying it at work, I compared the code and noticed that I had left out one thing, which made it work:
This line:
pickerController.displayedProperties = [NSNumber(int: kABPersonPhoneProperty)]
I never thought of this as being the problem, since the image showed in the contacts view. Of course I now need to know how to include the UIImage of the contact in that list, but since it isn't available like kABPersonPhoneProperty I really don't know how to do this.
Is it maybe a bug? Shouldn't I be able to get the Image, even if the above line excludes everything but the phone numbers?
My workaround would be to implement
func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController!, didSelectPerson person: ABRecord!) {
//get the image, then hide everything except phone numbers
}
and then define what's hidden in the contacts view in the next step. But that wouldn't be very nice would it?
Maybe someone knows of a better solution. Many thanks!
Well, seems like there is no problem here after all. I just tried the code of my first post again and it works. On my device AND on the same simulator...
Since I first had this problem I reinstalled Xcode, maybe that solved it without me noticing. Weird bug...
Nonetheless: (non-)problem solved!
I guess the reason you always receive false from ABPersonHasImageData is your code doesn't have the permission to access any AddressBook data except for the data the user explicitly selected (phone number, in your case).
To request the permission, wrap your presentViewController: ... in ABAddressBookRequestAccessWithCompletion (or acquire the permission at some other point, but before you attempt to access the picture).
e.g.
ABAddressBookRequestAccessWithCompletion(nil) {
(granted:Bool, err:CFError!) in
dispatch_async(dispatch_get_main_queue()) {
if granted {
// TODO: present ABPeoplePickerNavigationController etc.
}
}
}