I have one SwiftUI - iOS app running, and I need to open the link from email/whatsapp/etc in my app.
So lets say the link is like this (from my website):
https://www.mapplebook.com/welcome;id=123
I have tried the custom Scheme, which works fine, but for that i need to do something like: myScheme://www.mapplebook.com/etc....
Which is bad because Website and Android only understand things without the scheme.
The universal link looks like the best approach, I read a couple of things about Apple docs and some other questions, but could not make it work. :(
Is there any suggestion? Maybe some tutorial that I am missing.
Any help is much appreciated.
Editing the question as requested:
This is my info.plist - In this case I am using the custom scheme mapplebook
In SceneDelegate.swift, I have the followng:
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
guard let url = URLContexts.first?.url else {
return
}
if let range = url.absoluteString.range(of:"https//www.mapplebook.com/id=") {
let sharedtoken = url.absoluteString[range.upperBound...]
//with sharedtoken i can redirect internally and open the correct view - working okay
}
}
But, as mentioned, that uses scheme mapplebook right?
Is it possible to have something like in android, where we say like:
android:host="mapplebook.com"
android:pathPattern="/something"
android:scheme="https" />
So it ask to open the https://mapplebook.com/something url in my app.
Thank you Koen for helping.
Related
Using the webview_flutter with evaluateJavascript(), I've been able to modify the style of most elements of my website, but can't understand why some elements don't get modified.
My WebView is included, and the website to display within the WebView is https://dme.com.sg/index.php?dispatch=auth.login_form
I've included a snapshot as well, showing how I can hide and modify the colours for most of the elements, yet it seems all those that are within the "form" cannot be changed.
Would appreciate any help on how I can modify those as well, especially to change their colours to a darker theme to match the colours of the app.
WebView(
initialUrl: 'https://dme.com.sg/index.php?dispatch=auth.login_form',
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (controller) {
_controller = controller;
},
onPageStarted: (url) {
_controller.evaluateJavascript(
"document.getElementsByClassName('tygh-top-panel clearfix')[0].style.display='none';"
"document.getElementsByClassName('tygh-header clearfix')[0].style.display='none';"
"document.getElementsByClassName('tygh-header')[0].style.display='none';"
"document.getElementsByClassName('tygh-footer')[0].style.display='none';"
"document.getElementsByClassName('auth-information-grid')[0].style.display='none';"
"document.getElementsByClassName('ty-breadcrumbs clearfix')[0].style.display = 'none';"
"document.getElementsByClassName('container-fluid content-grid')[0].style.background = 'black';"
"document.getElementsByClassName('ty-mainbox-title')[0].style.color = 'pink';"
"document.getElementsByClassName('buttons-container clearfix')[0].style.display = 'none';"
);
},
),
Have kept tinkering around with it, and looking up JavaScript tutorial, and I managed to find a solution. So I'm not sure HOW or WHY, so still hoping someone could comment a response that explains so I can better understand.
Something else I've learnt, it's easier to just use the "console" tab of chrome to test the java scripts on the page before moving it into flutter webview.
Using the "document.getElementsByClassName("buttons-container clearfix")" command, I got a list of where the class was being used, and found the one I wanted to change was 1. It helps that when as you type the right index number, it gets highlighted on the website.
So then using "document.getElementsByClassName("buttons-container clearfix")1.style.background = 'black'" I managed to change the style of the element I wanted.
I've included a screengrab of the chrome console here if it can help anyone else.
This question already has answers here:
UIImage(contentsOfFile:) returning nil despite file existing in caches directory [duplicate]
(1 answer)
NSURL path vs absoluteString
(3 answers)
Closed 6 years ago.
EDIT: The questions linked to in the duplicate section answer this question quite well (I just hadn't found them when I posted this). Please refer to those.
I have just started looking into Swift (as of about three or four days ago), and have encountered a problem that I really do not understand, and for which I could not find anything already written about. I had already seen Read and write data from text file, and borrowed some of the code from the accepted answer there, but I'm still left with a question.
I was having some file IO trouble elsewhere, so in order to experiment and make sure I understood everything, I created a brand new single view app for iOS 10, to experiment with. All I have added is the following to the viewDidLoad() function in the view controller (sorry it is a bit messy):
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let mydata = "I like to eat food!".data(using: .utf8)
let mydata2 = "Tigers are a man's best friend".data(using: .utf8)
let dir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! as URL
let fURL = dir.appendingPathComponent("hello.txt", isDirectory: false)
NSLog(fURL.absoluteString)
do {
if !FileManager.default.fileExists(atPath: fURL.absoluteString) {
let createdFile = FileManager.default.createFile(atPath: fURL.absoluteString, contents: mydata2!, attributes: nil)
NSLog("File created? \(createdFile)")
}
try "The other string!".write(to: fURL, atomically: true, encoding: .utf8)
if !FileManager.default.fileExists(atPath: fURL.absoluteString) {
let createdFile = FileManager.default.createFile(atPath: fURL.absoluteString, contents: mydata2, attributes: nil)
NSLog("File created? \(createdFile)")
}
try mydata2?.write(to: fURL)
let filehandle = try FileHandle.init(forWritingTo: fURL)
filehandle.truncateFile(atOffset: 0)
filehandle.write(mydata!)
} catch {
NSLog(error.localizedDescription)
}
}
I then run that through Xcode 8's simulator, and watch the documents folder for the app. The lines which use a write() function appear to work fine. A .txt file named hello.txt is created, and filled then re-filled with the data that is written out. The createFile lines however appear to fail, with createdFile always coming out as false, and no file appearing in the directory. The obvious difference between them is that the createFile lines use fURL.absoluteString, rather than the URL - unfortunately there doesn't seem to be a function in FileManager to use the URL as of right now.
When I tried using the absoluteString with one of the write functions, I got an error informing me that it failed because the folder "hello.txt" doesn't exist, which leaves me thoroughly confused because I don't quite follow how the code thinks that is supposed to be a directory, especially when use the isDirectory
So, clearly I am not understanding something and doing something wrong, but I can't see what. Can someone please explain the correct approach if I want to simply create a file ready for future write(s)? I should be able to use the fileHandle approach, but it seems strange to me that the other shouldn't work.
After the Swift 3 update, I'm having some trouble getting my app to compile. Most of the errors are pretty simple to fix, but I'm running into a few in particular with AWS. Is there some sort of updated AWS SDK for Swift 3? I've tried to look it up, but haven't found one. In any case, the two main errors I'm having trouble resolving are as follows:
"Type 'IdentityProviderManager' does not conform to protocol AWSIdentityProviderManager." This is for a class I created following a tutorial to set up logins through AWS Cognito. The code is:
class IdentityProviderManager: NSObject, AWSIdentityProviderManager{
var tokens : [NSString : NSString]?
init(tokens: [NSString : NSString]) {
self.tokens = tokens
}
#objc func logins() -> AWSTask<AnyObject> {
return AWSTask(result: tokens as AnyObject)
}
}
In the AWS documentation for AWSIdentityProviderManager, it says that the only required function is logins, which I have. Is there a simple way to resolve this that I'm missing?
The other error is in my LoginViewController class: "Type 'LoginViewController' does not conform to protocol 'AWSCognitoIdentityPasswordAuthentication'." Here the issue seems a bit more clear, since the documentation says that getPasswordAuthenticationDetails() is a required method and XCode seems to have changed this method to getDetails() when updating to Swift 3, unless I'm mistaken and it wasn't there to begin with or something. In any case, autocomplete doesn't give me the original method and I can't seem to make the class conform to the protocol.
Apologies if the answer is already in documentation somewhere, but as far as I can tell it seems like the AWS SDK (at least the version that I have) is somehow incompatible with Swift 3. Is there something I can do to resolve these errors?
Nevermind, it turned out XCode just wasn't showing me the option to make the changes I needed. The automatic fix implemented slightly different versions of the required functions and everything ended up working.
Hi all I am on a tutorial for maps but it is using Xcode 7 in the tutorial.
In the tutorial he uses this link but it has been stopped in the new version.
Can anybody let me know the best way to duplicate this?
I have added NSLocationWhenInUseUsageDescription in the plist.
func locationAuthStatus() {
if CLLocationManager.authorizationStatus() == .authorizedWhenInUse {
map.showsUserLocation = true
}else {
//cant get this to work in ios10
locationManager.requestWhenInUseAuthorization()
}
}
Any help will be appreciated.
solved....
I realised that I had created a constant named locationManager but spelt it lacationManager instead, I couldn't work out why it was asking me to change it to LacationManager then I realised the spelling mistake.
all works fine now.
I search for a way to test my extbase-extension. I work with two different templatepaths for front- and backend.
module.myext{
view {
templateRootPath = myext/Resources/Private/Backend/Templates/
partialRootPath = myext/Resources/Private/Backend/Partials/
layoutRootPath = myext/Resources/Private/Backend/Layouts/
}
}
The backendmodule works without any problem, but my test will not get the different templatepath. If i write the view.templateRootPath to config.tx_extbase in the ext_typoscript_setup.txt it works, but in this case all my frontendtests do not work any more. The simplest way to resolve this issue is to merge the templatepaths and work with only one, but there must be a way around this solution.
Does somebody has an idea?
Did you statically include the extension setup in your root page?
Then the backend module should work as long as you include it in the web tools and select the root page in the page-tree...
If you include your module in the user tools, this is a known bug. See here:
http://lists.typo3.org/pipermail/typo3-project-typo3v4mvc/2011-December/011174.html
You could put this code in your *ext_localconf.php*:
if (TYPO3_MODE === 'BE') {
t3lib_extMgm::addTypoScript($_EXTKEY, 'constants', $tsIncludeConstants);
t3lib_extMgm::addTypoScript($_EXTKEY, 'setup', $tsIncludeSetup);
}
where $tsIncludeXXis your TS code to include the configuration files of your extension:
$tsIncludeConstants = "<INCLUDE_TYPOSCRIPT: source=FILE:EXT:$_EXTKEY/Configuration/TypoScript/constants.txt>";
$tsIncludeSetup = "<INCLUDE_TYPOSCRIPT: source=FILE:EXT:$_EXTKEY/Configuration/TypoScript/setup.txt>";
This is kind of brute force, but it works...