mobile plugin

mobile plugin

by y h -
Number of replies: 18

Hi,

I asked already a question about how to add a plugin and I followed these Steps:

1. Enable debugging, Disable all caches (Im not sure what i have to do to disable all caches so please if you can tell me what I have to do), Enable WebServices in Advanced options, Enable WebServices protocols (REST), Enable Mobile Services (in Plugins -> WebServices-> Services)

2. Find the full source code here: https://github.com/cvaconsulting/moodle-local_custommm

3. Unzip this folder in /moodle/local folder

4. Go to Home > Site administration > Plugins > Web services > External services

5. Add a new external service: custommm for ex.

6. When creating, the flats "Can download files" and "Enabled" must be checked

7. Add the following functions:

local_custommm_get_grades

local_custommm_update_grade

local_custommm_get_forums_by_courses

local_custommm_get_forum_discussions

local_custommm_get_forum_posts

8. Go to phpMyAdmin/yourdatabase/ mdl_external_services table and add manually a shortname for the new Service

9. Edit the config.json file and change the wsservice parameter in order to point to the shortname of the Service you created before:

"wsservice" : ["moodle_mobile_app", "custommm"],

10. Add also the name of the plugin you are developing at the final of the plugins parameter:

"plugins" : ["notifications", "upload", "contents", "participants", "addcontact", "addnote", "sendmessage", "grades"],

11. Notice that, for avoid errors, this last change should be done once the file plugins/grades/main.js file exists

12. Find the full source here: https://github.com/cvaconsulting/moodlemobile-grades

13. Unzip the folder in /assets/www/plugins

Then I run my app from eclipse:

Sometimes i have a white screen and sometimes everything is ok and i have a "grades" under the course with contents and participants but after two minutes i have a white screen or a message as the following:

"we lost connection, you need to reconnect. Your token is now invalid." then a white screen .

Please help me to solve this problem and if any of the steps that i followed is wrong please tell me and don't forget to tell how can i disable all caches.

Thanks in advancesmile

Average of ratings: -
In reply to y h

Re: mobile plugin

by Jason Parks -

Hello,

I am also experiencing the same issue with the invalid token and connection being lost,

any help would be appreciated.

In reply to y h

Re: mobile plugin

by Juan Leyva -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Hi,

I recommend you to test and develop using Chrome or Chromium. Mainly because you can enable there the developers tools and analyze all the Xhr request s (ajax calls) so you can see what errors you receive

The token error occurs when web services are failing.

See the developers docs where you will find instructions for setting up Chrome

Regards

In reply to y h

Re: mobile plugin

by Khyam Shahzad -

I am also facing the same problem.

MOODLE Version: 2013111801.01
MM App version: 1.4 (versioncode: 371)

In config.json, it only accepts "string" for "wsservice" attribute (default: moodle_moible_app). If I try to replace it with an array like 

"wsservice" : ["moodle_mobile_app", "custommm"]

then I couldn't even get login. The error message is "Web service is not available (it doesn't exist or might be disabled)"

(My new custom web service is working fine with client.php but not in Mobile App.  I have noticed that the token for each web service moodle_mobile_app and custommm is different and that's why it gives the error message "we lost connection, you need to reconnect. Your token is now invalid." then a white screen .)

Any help will be highly appreciated. 

In reply to Khyam Shahzad

Re: mobile plugin

by y h -

At least if anybody could tell us if this syntax is correct:"wsservice" : ["moodle_mobile_app", "custommm"], or if we should edit something else then the steps that i posted earlier.

In reply to y h

Re: mobile plugin

by Juan Leyva -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Nope, it should be "wsservice": "custommm"

 

May you follow this tutorial: http://www.slideshare.net/juanleyva/moodlemoot-spain-2013-taller-creacion-de-un-plugin-para-moodle-mobile

 

In reply to Juan Leyva

Re: mobile plugin

by y h -

Hi,

The tutorial that you mentioned is the one that I followed to add the plugin and concerning your advice about using chrome ripple, I don't know why but the ripple isn't working for the index.html of the moodle mobile app it keeps giving a white page....

Thank you for your help and if someone faced the same problem and figured out a solution please tell me. Thanks in advancesmile

In reply to y h

Re: mobile plugin

by Juan Leyva -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Please, read this tutorial about Chrome developer tools so you can debug the application

https://developers.google.com/chrome-developer-tools/?hl=es

In reply to Juan Leyva

Re: mobile plugin

by y h -

Now I am able to access the app from chrome and the error is:

  1. Uncaught TypeError: Cannot read property 'id' of null mm.cache.js:50
    1. MM.cache.getElementmm.cache.js:50
    2. MM.lang.loadPluginLangmm.lang.js:138
    3. MM.registerPluginmm.js:841
    4. (anonymous function)main.js:100
    5. i.execCbrequire.js:29
    6. $.checkrequire.js:18
    7. (anonymous function)require.js:23
    8. (anonymous function)require.js:8
    9. (anonymous function)require.js:23
    10. vrequire.js:7
    11. $.emitrequire.js:23
    12. $.checkrequire.js:19
    13. $.enablerequire.js:23
    14. $.initrequire.js:17
    15. (anonymous function)require.js:21
    16. (anonymous function)require.js:8
    17. text.finishLoadtext.js:152
    18. (anonymous function)text.js:188
    19. xhr.onreadystatechange

And using Firefox the app gives me an error box saying: No permission to create web service token for the service custommm

In reply to y h

Re: mobile plugin

by Juan Leyva -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Hi,

you need to enable the capability moodle/webservice:createtoken for the Authenticated User Role in the System context

Regards

In reply to Juan Leyva

Re: mobile plugin

by y h -

I added moodle/webservice:createtoken in the Required capability of the custommm service and enabled 'Authorised users only' but I still have the same error as the above and an error box: we lost connection, you need to reconnect. Your token is now invalid. Should I  edit or add anything else?

In reply to y h

Re: mobile plugin

by Juan Leyva -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

You have to monitor the AJAX requests when you got this error, because it returns an error code/information

In Chrome, with the Developers tool open, go to Network. Enable the filter (click on the filter icon, and select XHR) there you can monitor every XHR request is sent to the server from the app so you can easily view in the Response tab the full error you got

Remember to enable in your Moodle installation the following: Admin / Development / Debugging / Show Developer erros and also check display errors checkbox

 

In reply to Juan Leyva

Re: mobile plugin

by Khyam Shahzad -

Thanks Juan,  I am getting the following error message..

 
{exception:webservice_access_exception, errorcode:accessexception, message:Access control exception,…}
  1. debuginfo"Access to the function core_get_strings() is not allowed.
    There could be multiple reasons for this:
    1. The service linked to the user token does not contain the function.
    2. The service is user-restricted and the user is not listed.
    3. The service is IP-restricted and the user IP is not listed.
    4. The service is time-restricted and the time has expired.
    5. The token is time-restricted and the time has expired.
    6. The service requires a specific capability which the user does not have.

    7. The function is called with username/password (no user token is sent) and none of the services has the function to allow the user.
    These settings can be found in Administration > Site administration > Plugins > Web services > External services and Manage tokens."
  2. errorcode"accessexception"
  3. exception: "webservice_access_exception"
  4. message: "Access control exception"
In reply to Khyam Shahzad

Re: mobile plugin

by Jason Parks -

Hello,

I have read through the previous posts and followed the correct steps, however, I am now having another problem.

I have ensured that authenticated users have permission to create token and I have ensured that the config.json file is all correct:

"wsservice" : "custommm",

I then try to log in to the app through ripple within chrome and I get a message saying "No permission to create web service token for the service custommm".

I then go through the moodle forms and create a token linking to the custommm web service and the user that I am trying to log in with. 

After this, I then go back to the app and attempt to log in again, this time, the app just goes to a white screen.

Any advice about where I am going wrong would be appreciated.

Many Thanks.

 

 

In reply to Jason Parks

Re: mobile plugin

by Khyam Shahzad -

I have fixed this issue...

Just add the MM standard functions in your external web service and use "wsservice" : "custommm" in config.json instead of "moodle_mobile_app" smile 

Enjoy

 

In reply to Khyam Shahzad

Re: mobile plugin

by y h -

It didn't work for me. Are you  sure that's all what you did??

In reply to Khyam Shahzad

Re: mobile plugin

by Jason Parks -

Thank you!

This fixed the issue for me as well.

 

In reply to Jason Parks

Re: mobile plugin

by Gary Lynch -

Hi

I have followed this post and the post here

https://moodle.org/mod/forum/discuss.php?d=228601&parent=1127937

but i am still getting the message alert on my phone

Alert

Uncaught Type Error: cannot read the property 'id' null

File:file:///android_asset/www/lib/mm.cache.js

line: 50

im using moodle 2.5

Galaxy S5

I have tried to use the forums plugin as a tutorial but i cant seem to narrow this one down

any help i would be grateful for

Regards

Gary