How to disable "turn-to-sleep" on Apple Watch? - ios

I'm working for an airline with their app. We have released the app on Apple Watch, but have a big problem: the scanners for the QR-code used to go through security and to board the plane, are scanning from the bottom and up...
This means that you cannot use the watch app, because when you turn your wrist, the watch goes in black sleep mode.
Is there any way of turning this temporarily off for a view? I have heard rumours that it can be disabled in WatchOS 4, but can't find out how.
Thanks for the help! :)

This is very interesting question. There seems no way to present this without the PassKit(Or even with passkit the screen will still go off...) I think PassKit Controller has some functions when you focus the QR code it doesn't go to sleep...
reading the watchkit reference in here , you need to implement presentation of the passkitController.
Because right now you cannot tell apple watch to resign sleep, it is agains human guidelines + it would really be energy-consuming solution. Instead, apple handles for you with PassKitController instance. So on watchkit, you do this:
let pass = PKPass(data: /*There goes your data*/, error: nil)
presentAddPassesController(withPasses: [pass]) {
// Do smth on completion
}
You definitely should try to inform user and give him access to export the pkpass to wallet...
Resources used:
https://github.com/TwoRingSoft/pkpassgenerator
For generating custom passkit object
This could help you as well:
https://www.natashatherobot.com/url-apple-wallet-passkit-pass/?utm_campaign=This%2BWeek%2Bin%2BSwift&utm_medium=email&utm_source=This_Week_in_Swift_138

Related

Posting to correct Instagram Account with UIActivityViewController

I am using UIActivityViewController to post images to Instagram app from MY app.
Please note my app does not use Instagram API or log in to users' Instagram Account.
let sharingImage = button.backgroundImage(for: [])
let avc = UIActivityViewController(activityItems: [sharingImage as AnyObject], applicationActivities: nil)
avc.excludedActivityTypes = [.addToReadingList,.airDrop,.assignToContact,.copyToPasteboard,.openInIBooks,.postToFacebook,.postToFlickr,.postToTencentWeibo,.postToTwitter,.postToVimeo,.postToWeibo,.saveToCameraRoll,.message,.mail,.print]
if let wPPC = avc.popoverPresentationController {
wPPC.sourceView = followUsButton
}
self.present(avc, animated: true, completion: nil)
I am logged into my Instagram App with multiple accounts. Upon share from MY app, Instagram tries to post to the account 'A' which is currently logged in (inside the Instagram app). This makes sense.
However, if I now switch to the Instagram app and switch to account 'B' inside it, go back to MY app and then try to share again, it continues to try to post to Account 'A'.
The only way to fix it, is to kill MY app and start it again and then it loads the correct currently logged in account 'B'.
Is there a way to programmatically reload the correct Insta account while sharing?
This is only a workaround however might be your only choice at the moment as you see that even native Photos has the same issue so it is rather down to Apple to fix it.
In your application's Info.plist, add a boolean key UIApplicationExitsOnSuspend with the value YES. See the Information Property List Key Reference for more information.
This way the app is getting terminated when enters a background state and once you go back to it it will get reloaded. The user might not notice the difference.
Perhaps before killing the app you could add some interface state saving function in:
optional func applicationWillTerminate(_ application: UIApplication)
I don't know how your app is laid out but you could create a singleton class which could be implementing Codable and keep tracking all the app state variables which would have a save and load function. Saving would be triggered upon termination and loading when app is launching.
I hope it will help in some way.
EDIT1: Should work in iOS 13
Below this code should work and terminate your app however it is not recommended and you might face an issue when uploading to AppStore. I guess you can challenge the rejection with the Apple review team by explaining that they have a bug in the SDK and point them to the problem.
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
UIApplication.shared.perform(#selector(NSXPCConnection.suspend))
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
exit(0)
}
}
Short answer, I doubt.
UIActivityViewController doesn't give you control over the user's login status (which is why it's interesting to use). IMO, that's a bug on Apple side. So, unless there's a secret way to clear the authorisation tokens that the iOS runtime has stored within your app memory, I don't see how you could possibly achieve what you want.
Plus, if Photos app has the same behaviour, that's not a good sign...
Just in case, when you say that the problem occurs when switching accounts, do you mean
In MY app, you immediately try to post from the same ViewController?
You move to a parent View (hence destroying the old one)back , then to the same view as 1/?
Do you have the same result in both case? I am asking because when instantiating a new UIActivityViewController in a new view, the runtime might fetch the new user login profile, while if you instantiate it from the same view that was used to post from the old account, it might not do so (hence it'll use the old login)
This is iOS issue not specific to your app.

Use ReplayKit to record any app on screen

I am trying to create an iPhone app that records not only the app's screen but if put into the background it records everything on the screen, including other apps. This is how recording from "Control Center" works. The difference is I want to get access to the video immediately without user intervention, with the user's consent of course.
I've implemented code using ReplayKit2 on iOS 12 that uses an embedded Broadcast Upload Extension. I have not found any examples online that work like this.
I posted the code on Bitbucket: https://bitbucket.org/breelig/replaykitbroadcasttofile/src/master/
The closet similar question I found on SO is: ReplayKit stops screen recording in background mode of the application or outside the app?
Update
Based on the good responses by #KaneCheshire and #AndreyA. below and other random sources I was able to develop a solution that works. Please see the code in my BitBucket link above.
From the docs:
Apps on a user’s device can share the recording function, with each
app having its own instance of RPScreenRecorder. Your app can record
the audio and video inside of the app, along with user commentary
through the microphone
The only other way to record the screen is through a Broadcast Upload Extension, which requires the user to initiate it through Control Centre.
I've faced almost the same problem that you did and it's absolutely lacking any kind of guides or documentation.
The way I resolved this problem to myself is setting nil to my preferred extensions, so it makes RPSystemBroadcastPickerView to show all of them including system screen video capture:
override func viewDidLoad() {
super.viewDidLoad()
let broadcastPicker = RPSystemBroadcastPickerView(frame: CGRect(x: 100, y: 100, width: 80, height: 80))
broadcastPicker.preferredExtension = nil
view.addSubview(broadcastPicker)
}
Also I've found one thing that I've figured out to be useful - this Twilio lib and its example - https://github.com/twilio/video-quickstart-swift/tree/master/ReplayKitExample - These guys have made a decent work in area of video/audio capturing and we can try to use their experience.
You can find your exactly preferedExtension here:
When you add pickerView.preferredExtension exactly the Bundle Identifier, your app will be showed on the Recording App List. Hope this helps!

PassKit Pass - Opening iOS app from a pass

I noticed a few PassKit wallet passes can open their originating app, right from the pass. The iOS app opens when the pass icon is clicked, for example in Delta Airlines passes.
I can't seem to find any documentation or examples on this. How can one add this to a PKPass?
You can use the appLaunchURL key in the passes’ pass.json.
https://developer.apple.com/library/archive/documentation/UserExperience/Reference/PassKit_Bundle/Chapters/TopLevel.html#//apple_ref/doc/uid/TP40012026-CH2-SW1

In custom iOS keyboard detect the app

How to detect in which app my custom keyboard used and show different button?
E.g. in Twitter I would add # to string I post into input field and in Reddit /r/
It is possible through following code. As you'll get bundle identifier of the app where you're using your custom keyboard.
Swift
let hostBundleID = self.parentViewController!.valueForKey("_hostBundleID")
let currentHostBundleID = String(hostBundleID)
print(currentHostBundleID);
From bundle identifier you can find app name easily.
Edit: See above. Things have changed.
This is not possible. An extension runs sandboxed and is only fed information from the API and cannot access anything else. The keyboard can only receive text context changes and activate/deactivate calls. Being able to detect an app lies outside of the extension sandbox and therefore is impossible.

iAd Producer - How to open a URL in safari?

I'm just doing some initial research into creating iAds with iAd Producer, but we'd like to link the ad to an external website, rather than an iTunes listing.
Is this possible, if so, how would you go about it? Ideally clicking on the ad would open the link in Safari, but if there is a UIWebView equivalent that would be fine too (The WebGL view control confusingly seems to be for displaying 3d objects).
Many thanks in advance.
Ted
I'm not familiar with iAds, what does it look like when specified in HTML?
According to this http://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Introduction/Introduction.html
it looks like it won't be recognized.
(This is s useful reference in this area: http://wiki.akosma.com/IPhone_URL_Schemes)
But if you load the page in a UIWebView you can intercept the iAds link within shouldStartLoadWithRequest: and launch Safari yourself from there.
Ah, I've realised now I was overcomplicating things somewhat / missed the easy answer.
The iAds produced by iAd Producer are all HTML, with Javascript added to handle page / control events. This should have given me the clue that they themselves are executing in some sort of UIWebView control.
Hence, when I added the following Javascript, on a button click event, the user is warned they are leaving the app (well they were when leaving the iAd Tester app) and then thrown out into Safari to view the website, as I wanted all along. Simple. I guess it's not really what Apple want people to do with iAds (it's not driving them to the appstore), hence it's not that well documented.
this.onViewTouchUpInside = function (event) {
document.location = "http://www.google.co.uk";
};

Resources