Ionic

> ionic config info: Bekijk info over huiig project (app_id, app_key, dev_push, gcm_key)

Code om device te registreren voor pushberichten:

  .run(function ($ionicPlatform, $rootScope) {
    $ionicPlatform.ready(function () {
      // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
      // for form inputs)
      if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
        cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
        cordova.plugins.Keyboard.disableScroll(true);

      }
      if (window.StatusBar) {
        // org.apache.cordova.statusbar required
        StatusBar.styleLightContent();
      }


      // kick off the platform web client
      Ionic.io();

      // this will give you a fresh user or the previously saved 'current user'
      var user = Ionic.User.current();

      // if the user doesn't have an id, you'll need to give it one.
      if (!user.id) {
        user.id = Ionic.User.anonymousId();
        // user.id = 'your-custom-user-id';
      }

      console.log("User id:", user.id);
      //persist the user
      // user.save();

      var push = new Ionic.Push({
        "debug": false,
        "onNotification": function (notification) {
          var payload = notification.payload;
          console.log(notification, payload);
        }
      });

      push.register(function (token) {
        $rootScope.token = token.token;
        console.log("token: ", token.token);
        push.addTokenToUser(user);
        user.save();
      });
    });
  })

Testen op mobiel:
- Sluit mobiel aan op pc dmv een USB-kabel.
- Run command: 
> ionic run android --device 
- Ik kreeg een error: ERROR: Error: Please install Android target: "android-22". Opgelost door optarten van SDK Manager, update what is updatable and install API22 > SDK Platform and Extras > Android Support Repository + Android Support Library + Google Play services + Google Repository
- Volgende error die ik kreeg was: ERROR: Failed to deploy to device, no devices found. Om er voor te zorgen dat Ionic de app kan deployen op je telefoon moet je zorgen dat het commando: adb devices wordt uitgevoerd (adb = Android Debug Bridge). Vervolgens verschijnt er een melding (Allow USB debugging) op je telefoon, deze moet je bevestigen. Zorg er ook voor dat debugging aanstaat en dat USB-debugging is ingeschakeld op je telefoon.
- Voer vervolgens het command: ionic run android --device -l -c uit. De applicatie wordt nu deployed op de telefoon. Bij de eerste keer kan dit even duren. De -l flag zorgt voor live reloading de app als je bestanden opslaat in je editor. De -c flag logt berichten naar de command console. Dus berichten die je in de console.log() zet worden in de command getoond.
- In de log verschenen bij mij steeds deze berichten:
  733965 warn No Content-Security-Policy meta tag found. Please add one when using the cordova-plugin-whitelist plugin.
Dit betekent dat je een meta tag moet toevoegen aan je index.html. Ik heb deze tag gebruikt: 


Overige Ionic commando's:

  • ionic serve --lab (start webserver en zie in de browser hoe de app er uit ziet op zowel een android-toestel als een iphone)
  • ionic share e-mailadres (Deel je app met iemand dmv het versturen van een mail)
  • ionic upload (upload je app naar ionic)


bron: http://chat.stackoverflow.com/transcript/93961

Reacties

Populaire posts van deze blog

[SQL Server] varchar vs nvarchar

MS Sql 70-461: Chapter 5

[C#] Class serialiseren en deserialiseren