codeigniter mobile detection and desktop version - codeigniter

I can get mobile site in mobile phones using the code below in the default controller index function. But I want to browse desktop version again in mobile. Since the code above resides in default controller index function, there is no way to browse desktop site in mobile, please help
public function index() {
$this -> load -> library('Mobile_Detect');
$detect = new Mobile_Detect();
if ($detect->isMobile()) {
header("Location: ".$this->config->item('base_url')."/mobile"); exit;
}
}

Maybe you can check if the device is mobile and then ask the user if they would like the mobile version or the full version, and then load one or the other.
Also take a look at this and see if it helps you.

Related

Codeigniter is_mobile function for Google bot

I am using codeigniter and I have mobile and desktop site.If user comes from mobile I am checking it with $this->agent->is_mobile() method then if user is mobile I am redirecting to mobile url.It works well for mobile devices.
But I am testing my site with this tool:https://www.google.com/webmasters/tools/mobile-friendly/ It is not redirecting to mobile website.I think is_mobile() method is not returning true for google mobile bot.
What should i do ?
You could use:
$this->agent->agent_string();
to return the user-agent and then manually check it against the googlebot user agents; see the link below for details of the user-agents currently in use by Google Webmaster Tools:
https://developers.google.com/webmasters/mobile-sites/references/googlebot
Had the same problem, apparently if the agent is detected as robot (in that case googlebot) it won't test if it's mobile too.
The following snippet is from the User_agent system library (line 150), look at the "break" instruction.
function _compile_data()
{
$this->_set_platform();
foreach (array('_set_robot', '_set_browser', '_set_mobile') as $function)
{
if ($this->$function() === TRUE)
{
break;
}
}
So you either remove the "break" or you extend the library.

Return different viewmodels in desktop and mobile versions for the same action in zend framework

In my zf2 application i have to show database records in mobile and desktop versions with different criteria and conditions. For mobile version i have used getUserMobileTable() function and for desktop version it is getUserDesktopTable() .
for mobile version my action should work as
public function userAction()
{
return new ViewModel(array('rowset' => $this->getUserMobileTable()->select()));
}
for desktop version it action should work as
public function userAction()
{
return new ViewModel(array('rowset' => $this->getUserDesktopTable()->select()));
}
What should be logic to do it? Will i need to use navigator.userAgent in javascript to detect agent? If so then how? Please help i've no idea about it as i'm new to zend framework.
You can use the Mobile Detect module to detect the user's device.
You could also do your logic in the same action and then select a different template like in this example

add a share button in Firefox OS application

I am creating a firefox OS application, I want the user to be able to share a link through any application installed and eligible (facebook, twitter etc). I saw android has this kind of feature and firefox OS has it as well, as I saw it in one of it's built in applications. Went through Web API, didn't find a suitable match,
Any ideas how to do it?
This is the intended use of the Web Activity API . The idea is that applications register to handle activities like share. The Firefox OS Boiler Plate app has several examples of using Web Activities. In that example a user could share a url using code like:
var share = document.querySelector("#share");
if (share) {
share.onclick = function () {
new MozActivity({
name: "share",
data: {
number: 1,
url: "http://robertnyman.com"
}
});
};
}
Any app that handles the share activity will be shown allowing the user to pick the proper app to handle the share.

Windows Phone: Navigate between apps

I have an app that needs to include a links to a second app in the same phone.
If the app is not installed the link should point to the windows store to install it (that part is working fine).
But if the app is already installed the link should go straight to the app and open it. How can I do that?
The app has two versions one form WP7 and other from WP8. if the solution is different for them please point the difference.
Thanks for the help...
I believe a URI Association is what you want. You should be able to create a different association in your WP7 app and in your WP8 app, and handle them accordingly.
A URI association allows your app to automatically launch when another app launches a special URI.
Also note:
If you are interested only in launching your own apps, consider using
APIs from the Windows.Phone.Management.Deployment namespace. You can
use this API to check for other apps that you’ve published, and then
launch them if they’re installed.
You basically just need to update the WMAppManifest.xml file to include the URI Association and then listen for that URI. Example:
<Extensions>
<Protocol Name="contoso" NavUriFragment="encodedLaunchUri=%s" TaskID="_default" />
</Extensions>
Then you can use a custom URI Mapper to handle your association (full example in top link above):
public override Uri MapUri(Uri uri)
{
tempUri = System.Net.HttpUtility.UrlDecode(uri.ToString());
// URI association launch for contoso.
if (tempUri.Contains("contoso:ShowProducts?CategoryID="))
{
// Get the category ID (after "CategoryID=").
int categoryIdIndex = tempUri.IndexOf("CategoryID=") + 11;
string categoryId = tempUri.Substring(categoryIdIndex);
// Map the show products request to ShowProducts.xaml
return new Uri("/ShowProducts.xaml?CategoryID=" + categoryId, UriKind.Relative);
}
// Otherwise perform normal launch.
return uri;
}
Hope this helps!
Is the secondary app one that you have created? If so, do something like this:
IEnumerable<Package> packages = InstallationManager.FindPackagesForCurrentPublisher();
foreach (Package package in packages)
{
if (package.Id.ProductId.ToString().ToLower() == "product id of secondary app")
{
//Launch the app
package.Launch();
}
}
Make sure that your publisher ids match in the WMAppManifest for both apps.
If this secondary app was published by someone else, you'll need to use a custom Uri schema. The app needs to have this feature added by the developer, you can't just launch any app.

Play 1.2.4 Mobile and PC design on the same app

I am a new developer in Play world! For a project I need to have a mobile and desktop version. But I don't know how to!!
Create 2 applications, share the model..;
Create a mobile controller to separate the desktop views against the mobile views
I have no idea of how to make this properly. I know the responsive design but I can't use it on this project.
Thanks
PS: Sorry for my english
Depending on the use case I would have a look at a framework like Twitter Bootstrap. With the twitter bootstrap you can use ONE set of view templates for both desktop and mobile. There is also a framework called Kickstrap and a few others.
But on the other hand, if you want to develop some sort of 'backend' or 'admin' application (you still CAN use twitter bootstrap, but you might have a look at frameworks like Sencha (EXT JS and Touch) or Kendo UI.
What ever you choose, Play will enable you to develop the serverside as it should be (RESTful), so the choice for the frontend can change in time, but you app architecture will be fine :-)
Either one is okay. As they are essentially the same thing, 2 set of routes/controllers/views plus 1 set of domain models.
If you are using my play clone, then you can simplified it to 1 set of domain model + 1 set of routes/controllers + 2 set of views, as you can do something like follows:
public class Application extends Controller {
...
#OnApplicationStart
public static class ViewRouter extends Job {
Controller.registerTemplateNameResolver(new ITemplateNameResolver(){
#Override
public String resolveTemplateName(String templateName) {
return UserAgent.isMobile() ? "mobile/" + templateName : templateName;
}
});
}
}
Thus you just put your mobile views under app/views/mobile and all others still remain in app/views, the template will be loaded dynamically based on the request's user agent, if it's coming from a mobile device then app/views/mobile/.. version get loaded otherwise, the normal view will be loaded.

Resources