I happen to have a lot of experience writing a Windows application in c#, where the async/await pattern has been a standard feature for years.
I can say from this experience that it's a great way to handle concurrency and I'm really happy that Apple is bringing this to Swift.
I'm often critical of language improvements that end up reproducing things you could already do with a different syntax, but in this case it's definitely worth it.
If you've never used async/await, it may initially look confusing. It looks like all you're doing is blocking your thread from running until another thread completes, but what really happens is that your thread returns at the point where the await keyword appears, and then resumes later when the result is available. So if your thread is the main thread, which is the most common case, using await doesn't block the main thread.
Exactly how the compiler manages to suspend and resume the thread without destroying your local variables, I don't know, but I'm sure they figured out a way that makes sense.
Frank
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Hi,
I'm trying to figure out how to manually position a subview within a view using SwiftUI.
For example, when the user taps the screen, I want to place a small icon on the screen at the position tapped.
I know how to get the coordinates of the tapped location but I don't know how to either place a view there or move an existing view already being shown to that location.
In a regular non-SwiftUI app I can set the frame, or set up constraints. I don't know what the best approach is in SwiftUI.
Thanks.
Hi,
I've been asked to estimate a project that would require ARKit, unfortunately I'm new to the technology and need some quick answers as to how it works.
The app my customer wants to build would overlay simple graphics at street addresses, as the user pointed their camera at buildings or storefronts.
For this to work, I'd need to be able to have the AR view tell me what map locations or street addresses are being seen in the camera view. Is this possible?
Thanks,
Frank
Is there any way to scan for Bluetooth advertising messages while in the background if the device doesn't advertise any service IDs?
I've been asked to build and app that does this. The device in question is an off-the-shelf medical alert button (my company doesn't make the device and can't alter its firmware). Upon examining it, I find that it does not advertise any service IDs nor does it offer any ability to connect, it works purely by sending advertising packets.
I'm told that there are Android apps that can work with this device even while in the background. I checked the iOS bluetooth docs to see if any new scanning capabilities had been recently added, but could not find anything.
Thanks,
Frank
Hi,
I'm looking at the function activityViewController(_:dataTypeIdentifierForActivityType:) in the UIActivityItemSource protocol. The documentation says "For items that are provided as data, returns the UTI for the item." The return type of the function is a String.
I don't know what "UTI" means in this context. The data I'm trying to provide is an HTML document (a string containing HTML). I tried returning "text/html", but I don't think this worked.
I'm also unsure whether my "itemForActivityType" function ought to be providing the HTML as a String, or perhaps converting it to Data first.
The end result I'm seeing is that I can share the HTML document via Mail, and it looks fine, but if I try to air drop it, I get an error that says "Extension request contains input items but the extension point does not specify a set of allowed payload classes."
I'd like my app to be able to share the HTML document via Mail or Airdrop. I don't care if it doesn't support sharing to any other services.
Thanks,
Frank
I'm trying to send my app silent push notifications by setting the "content-available" flag to 1 in the notification payload. This works, but there is a problem: if my app is not running in the foreground, the notification is visible on the home screen. I don't want this: I just want the app to see it, without waking up the screen or alerting the user.
If the app is open when the notification comes in, it works as expected; I receive the notification inside my app, and iOS does not display any alert or banner.
I configured my app with the "Remote Notifications" background mode.
What am I doing wrong?
I can't get my latest iPhone app to run in portrait mode only. In Xcode I've checked only the box that says "Portrait" under Device Orientation, and I've also examined the Info.plist file to ensure that there aren't any hidden settings for other orientations.
I've also tried checking or un-checking iPad, and checking "Requires Full Screen" when that option appears. No matter what I do, when I run the app on my phone and rotate the screen, the interface rotates.
What am I doing wrong?
I've got an iOS project that I've been working on for some months. Just recently, I started seeing a compiler error to the effect that "Referencing instance requires that X conforms to Equatable". It shows up in places where you'd expect something to be Equatable, such as the argument to firstIndexOf: on an array.
The class in question is written in Swift, but descents from an Objective-C base class. I know there are some issues with how Equatable interacts with Obj-C but I think I've done it right. The base class extends NSObject, and the subclass implements both the isEqual function and the static == function. (I don't think the latter is necessary but I included it just in case).
I've tried explicitly including "Equatable" in the definition of the subclass but the compiler rejects this as "Redundant conformance to protocol". I'm not exactly sure how that works since NSObject doesn't extend Equatable but I guess Swift considers them equivalent.
Here's where things get super weird though. Xcode still builds and runs the project despite the compiler error, and the code runs, and it works. I even put a breakpoint in the isEqual function to make sure it was getting called. Also, when I clean and rebuild the project, the compiler error often disappears for some time, reappearing hours or days later. So I think this must be some kind of bug in Xcode or Swift itself.
What do you think?
Frank
Views A and B are equal in width (set up via a constraint). The actual width will vary at runtime.
What I want to do is arrange view A such that it is horizontally centered on B but offset to the left by 1/10th of the total width.
In other words, if views A and B were 100 units in length, I'd want A to be positioned 10 units to the left of B. If the width were 150 units then the A position would be 15 to the left, etc.
I thought I could do this with either a leading constraint or a centerX constraint using a multiplier of 0.9, but it isn't working out the way I want.
What's the best solution?
Do string functions such as "replacingOccurrences" and "trimmingCharacters" always return a new string, even if the old string did not need to be modified?
In other words -- if I'm doing a large number of "replacingOccurrences" in my app but only a small number of the strings actually contain the sequence I want to replace, should I check to see if the sequence exists before calling replacingOccurrences, in order to avoid an unnecessary string allocation?
I would guess that Swift would return the same string if it didn't require any modifications, but the documentation just says "Returns a new string".
Thanks,
Frank
I'm getting the dreaded "Failed to prepare the device for development" error when I connect my iPhone running iOS 15 to the latest version of Xcode. I've tried rebooting both devices. How do I fix this?
Is there any way an account owner can authorize a different user to accept updated license agreements?
I manage multiple apps on behalf of customers, most of whom fail to accept these agreements until the day they need me to publish a new app and I have to hunt them down and ask them to do it. If it were one or two customers it wouldn't be a big deal, but I have nearly 40 of them, and this happens several times per year. It's a major hassle.
I often get crash logs where nothing in the stack trace is my code, other than an entry point in main. I don't know how to use these to figure out where the problem is. For example this one,
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 0
Last Exception Backtrace:
0 CoreFoundation 0x1c21cf180 __exceptionPreprocess + 228 (NSException.m:172)
1 libobjc.A.dylib 0x1c13a79f8 objc_exception_throw + 56 (objc-exception.mm:557)
2 UIKitCore 0x1ee572b1c -[UINavigationController pushViewController:transition:forceImmediate:] + 2312 (UINavigationController.m:7317)
3 UIKitCore 0x1ee5720b0 -[UINavigationController pushViewController:animated:] + 664 (UINavigationController.m:7272)
4 UIKitCore 0x1ee62ae9c -[_UIViewControllerTransitionCoordinator _applyBlocks:releaseBlocks:] + 264 (UIViewControllerTransitioning.m:1121)
5 UIKitCore 0x1ee62725c -[_UIViewControllerTransitionContext _runAlongsideCompletions] + 140 (UIViewControllerTransitioning.m:374)
6 UIKitCore 0x1ee626f34 -[_UIViewControllerTransitionContext completeTransition:] + 132 (UIViewControllerTransitioning.m:286)
7 UIKitCore 0x1ee6371f4 __53-[_UINavigationParallaxTransition animateTransition:]_block_invoke.118 + 740 (_UINavigationParallaxTransition.m:393)
8 UIKitCore 0x1ef032d1c -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 752 (UIView.m:12852)
9 UIKitCore 0x1ef009a74 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 312 (UIView.m:0)
10 UIKitCore 0x1ef00a048 -[UIViewAnimationState animationDidStop:finished:] + 296 (UIView.m:2111)
11 UIKitCore 0x1ef00a0e8 -[UIViewAnimationState animationDidStop:finished:] + 456 (UIView.m:2130)
12 QuartzCore 0x1c671f3c8 CA::Layer::run_animation_callbacks(void*) + 284 (CALayer.mm:6680)
13 libdispatch.dylib 0x1c1c0d7d4 _dispatch_client_callout + 16 (object.m:511)
14 libdispatch.dylib 0x1c1bbb008 _dispatch_main_queue_callback_4CF$VARIANT$mp + 1068 (inline_internal.h:2441)
15 CoreFoundation 0x1c2160b20 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12 (CFRunLoop.c:1813)
16 CoreFoundation 0x1c215ba58 __CFRunLoopRun + 1924 (CFRunLoop.c:3113)
17 CoreFoundation 0x1c215afb4 CFRunLoopRunSpecific + 436 (CFRunLoop.c:3247)
18 GraphicsServices 0x1c435d79c GSEventRunModal + 104 (GSEvent.c:2245)
19 UIKitCore 0x1eeba7c38 UIApplicationMain + 212 (UIApplication.m:4353)
20 therapeutic-listening 0x100b83380 main + 88 (main.m:16)
21 libdyld.dylib 0x1c1c1e8e0 start + 4 (:-1)
Thread 0 name:
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x00000001c1d6b0dc __pthread_kill + 8 (:-1)
1 libsystem_pthread.dylib 0x00000001c1de4094 pthread_kill$VARIANT$mp + 380 (pthread.c:1492)
2 libsystem_c.dylib 0x00000001c1cc3ea8 abort + 140 (abort.c:94)
3 libc++abi.dylib 0x00000001c1390788 abort_message + 132 (abort_message.cpp:75)
4 libc++abi.dylib 0x00000001c1390934 default_terminate_handler() + 308 (cxa_default_handlers.cpp:68)
5 libobjc.A.dylib 0x00000001c13a7e00 _objc_terminate() + 124 (objc-exception.mm:693)
6 libc++abi.dylib 0x00000001c139c838 std::__terminate(void (*)()) + 16 (cxa_handlers.cpp:66)
7 libc++abi.dylib 0x00000001c139c8c4 std::terminate() + 84 (cxa_handlers.cpp:97)
8 libdispatch.dylib 0x00000001c1c0d7e8 _dispatch_client_callout + 36 (object.m:514)
9 libdispatch.dylib 0x00000001c1bbb008 _dispatch_main_queue_callback_4CF$VARIANT$mp + 1068 (inline_internal.h:2441)
10 CoreFoundation 0x00000001c2160b20 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12 (CFRunLoop.c:1813)
11 CoreFoundation 0x00000001c215ba58 __CFRunLoopRun + 1924 (CFRunLoop.c:3113)
12 CoreFoundation 0x00000001c215afb4 CFRunLoopRunSpecific + 436 (CFRunLoop.c:3247)
13 GraphicsServices 0x00000001c435d79c GSEventRunModal + 104 (GSEvent.c:2245)
14 UIKitCore 0x00000001eeba7c38 UIApplicationMain + 212 (UIApplication.m:4353)
15 therapeutic-listening 0x0000000100b83380 main + 88 (main.m:16)
16 libdyld.dylib 0x00000001c1c1e8e0 start + 4 (:-1)
I'm working on a screen where the goal is for the user to walk for 6 minutes while the app times them and measures the distance walked. I'm using CMPedometer to track the walking distance and a repeating 1-second Timer to count down the time.
This works fine as long as the app is in the foreground, but I'd like my user to be able to lock their phone and put it away while they walk. I used UIApplication.shared.beginBackgroundTask, but it doesn't provide enough time. It usually only gives me around 30 seconds. I also tried calling UIApplication.shared.beginBackgroundTask again or calling it once every time the timer ticks, with no better result.
How can I accomplish my goal here?
My company did an app for a customer 10 years ago. The app has in-app purchases (not subscriptions). It is an Objective-C code base. Over the years we've done minor updates to this app in order to keep it in compliance, but no major overhaul.
The app has been pretty reliable in the past, but recently my customer is getting a flood of complaints from users who say their in-app purchases disappear and can't be restored. It's happening too often to just be a case of bad internet connection or similar issue. The only thing that seems to be consistent is that it's never US-based users.
Whenever I test this app using sandbox accounts, I cannot reproduce the problems that are being reported. I'm always able to make purchases and restore them after reinstalling the app, or restore them to a different device. The content associated with the purchases always downloads correctly, even if I intentionally interrupt and restore internet access.
What can I do to figure this out? Should an IAP based app from 2014 be expected to work correctly today? Are there new legal issues with non-US app stores that we need to be aware of?
I realize there isn't a lot to go on here, but I don't have any more information.
Thanks,
Frank