可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I've a website which is already developed using PHPFox and it's working fine. Now, iOS development team has created a mobile app in iOS for the same functionality as of the website. User can do all the operations using this app which he/she can do on a website. In other words we can say this app is a replica of the existing website. The only restriction in development of app is that the flow and functionality should be same as of the website. There should not be any functionality discrepancy between the app and the existing running website.
For this app, they are using the same functions present into the website's PHPFox code base. I'm making the iOS team these functions available by means of REST APIs developed using Slim framework. In these APIs I'm accepting the request in JSON format from the app, decode it, call the required function from PHPFox code base by passing the required request parameters, get the response from the function, convert it into JSON format and send it back to the mobile app.
Now, let's focus on the issue I'm facing.
In both the scenarios(website and app) for some functionalities like new user account activation link, resend account activation link, reset existing user's password if he/she forgets password, etc. an email is sent to the concerned user. This email contains the relevant hyperlink. When user clicks on this hyperlink sent into the email, it always redirects to the respective web page on website.
When that specific user clicks on the hyperlink present into the received mail it gets redirected to the website only. It doesn't redirect to the app.
My requirement is if user has opened the mail on to the device which also has installed/runs the mobile app and clicks on a hyperlink in a mail he/she should redirect to the specific page of mobile app not the website.
And suppose if user has opened a mail on a computer, laptop or a device where the app is not installed he/she should redirect to the website.
How should I achieve this?
One more thing to be noted here is the redirection path(value of the href attribute) of the link to be send into the mail is generated into the website's PHPFox code only. So, if I need to make change into the logic to achieve this new functionality how should I do without changing the system flow on app and website? Or should I write a new function for it in order to not change the existing code of PHPFox?
I researched about the solution to this issue. I came to know about Bitly that could do this job but couldn't understand how.
This requirement is raised by iOS team to me (PHP team) on the basis of this hyperlink article they have found on the internet. Please refer this also.
So, my straight-forward question is since this article is about iOS coding and it nothing has to do with server-side coding (i.e. PHP) should I have to do anything on server-side using PHP to achieve this functionality?
回答1:
You (or your iOS-team) need to add an URL scheme to the iOS app to make deep linking possible. Then you need a website which checks if this URL scheme (and therefore the iOS app) is available on the device. If yes, then you forward to the app, if no you forward to the website. Then you embed the link to the check website in your emails.
There are services, which can help you with the whole setup. One I know is https://branch.io but I'm sure there are more out there.
Edit:
Deep Linking in iOS: http://blog.originate.com/blog/2014/04/22/deeplinking-in-ios/
From that link: "To enable deep linking, go to the Info tab in the Xcode project. In the URL Types section, click on the + button, and then add an identifier and a URL scheme. Ensure that the identifier and URL scheme you select are unique. Take note of the URL scheme you enter, as this is how iOS knows to open a link in your app."
There are more steps to follow, so make sure to read the whole thing.
Create a link for iOS and Web:
Create a link that either launches iOS app, or redirects to app store
and
Is it possible to register a http+domain-based URL Scheme for iPhone apps, like YouTube and Maps?
instead of redirecting to the AppStore, you'd like to redirect to your webpage.
回答2:
You do not have to do anything. Ask your iOS developers to read about URL Schemes
which seems to have been explained in the link you mentioned based on which the iOS team has contacted you. That link shows how you can make your app capable of being launched from another place(app-in your case the mail app). The reason why the email takes the user to the website and not the app is because the hyperlink mentions your web link and says nothing about the app.
Basically similar to how your website has a link of the form sayhttp://youwebsite.com/
, the app also has a link of the for yourapp://
which works on the device once the iOS app has integrated URL scheme
. So you need to mention this URL in the email hyperlink.
Refer to this answer which might help you to setup the mail link.
So to sum up,
- You need to do nothing
- iOS team needs to integrate URL Scheme
- The place from where the email is generated make sure the link is updated appropriately
P.S.: Use the link above for figuring out how the link is to work, haven't explained it here for 2 reasons,
a) Its beyond the scope of the questions, you needed to know if you need to do any change as PHP developer, So Answer is NO.
b) It is already addressed in this answer
回答3:
Using javascript, you can have a landing page to tunnel the users:
You can redirect the user to an app scheme using the following:
document.location="myApp://myUrl";
If the browser does not find the uri scheme, you can use a setTimeout to redirect the user to your webpage
setTimeout(function() {
document.location="/path/inside/website.html";
}, 100);
Another good solution would be to test the existence of the url schema using an iframe on a small test file, and redirect the current page if the iframe can be loaded
<iframe id="ifrm" src="" style="display:none"></iframe>
<script>
window.frames['ifrm'].onload = function() {
document.location="myApp://myUrl";
};
window.frames['ifrm'].src = "myApp://myUrl/ok.txt";
</script>
回答4:
As my Understanding the solution is simple.
Whenever user request for forgot password or create new account..etc. you have to identify that user send request from iPhone or Website
, if the User send request from website you have to pass activation link for web-page else you have to send link for app like this "itms-apps://itunes.apple.com/app/idyourappID", according to me for identified this PHP team have to get one more parameters from development team which is used to identify the device like 'web'
or 'mobile'
so that your problem will be solve.
Hope this will help you.
回答5:
You'll never know from where the user will open the link app or desktop until the user actually opens it.
So I would try to proxy the URL based on the user agent.
Here is an example on how to do it in nginx.