0

I have built a simple ionic app to test my api. But I ran into problem because when I run it in live-reload mode (-l option) everything works just fine (ionic run ios -l). But when I did not use live-reload (ionic run ios), it is seems that my app got an error. I cannot debug where my apps went wrong because that require live-reload option which an error won't occur.

I have reinstall the whitelist plugins several times. I added the below line into my config.xml inside widget zone.

<access origin="*"/>
<allow-intent href="*"/>
<allow-navigation href="*"/>

and also the below line in inside my index.html

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src &apos;self&apos; &apos;unsafe-inline&apos;; script-src &apos;self&apos; &apos;unsafe-inline&apos; &apos;unsafe-eval&apos;">

this is my controller code

var url="/api/event/new"

.controller('Test', function($http, $scope) {
    $http.get(url).then(function(data) {
        $scope.allEvents = {
            all : function() {
                return data.data;
            },
            remove: function(Events) {
                data.data.splice(data.data.indexOf(Events), 1);
            },
            get : function(_id) {
                for (var x in data.data) {
                    if(data.data[i]._id == _id) {
                        return data.data[i];
                    }
                }
                return null;
            }
        };
        $scope.isNotConnected = false;
    }, function(error) {
        $scope.allEvents = {
            all : function() {
                return [{"title" : "Connection error!"}];
            }
        }
        $scope.isNotConnected = true;
        console.log(error);
    });
})

This is my ionic info

Cordova CLI: 6.1.1
Ionic Framework Version: 1.3.1
Ionic CLI Version: 1.7.15
Ionic App Lib Version: 0.7.2
ios-deploy version: 1.8.6 
ios-sim version: 5.0.8 
OS: Mac OS X El Capitan
Node Version: v5.9.1
Xcode version: Xcode 7.3 Build version 7D175 
Wakeme UpNow
  • 523
  • 1
  • 4
  • 22
  • Also if I use ionic serve. I wouldn't be able to connect to my server at all. Even after I added proxies into ionic.project. – Wakeme UpNow Jun 01 '16 at 15:39
  • You are getting the url `/api/event/new`, but that doesn't really tell the app where to go. It sounds like you'll need to specifically tell the controller the hostname of the server – Jaron Thatcher Jun 01 '16 at 15:50
  • I ran into a similar problem not that long ago, check this question/answer out and see if it helps at all http://stackoverflow.com/questions/36731512/phonegap-doesnt-want-to-use-rest-service-no-matter-what-i-do – Jaron Thatcher Jun 01 '16 at 15:53
  • To Jaron That her - In my config files I added "proxies" : [{ "path" : "/api", "proxyUrl" : }]. I assure that my server is running (I tested it with my browser). – Wakeme UpNow Jun 01 '16 at 16:00
  • I was unfamiliar with Ionic config, but I looked it up and that does seem to be correct. I'll let you know if I think of anything else – Jaron Thatcher Jun 01 '16 at 16:05
  • Well, I got 404 error when using ionic serve – Wakeme UpNow Jun 01 '16 at 16:14
  • I found out that when I change my var url from '/api/event/new' to my actual address. It works perfectly. So I guess am not going to use ionic serve for a while (since I have to use proxies to avoid CORS problem) – Wakeme UpNow Jun 01 '16 at 17:44

1 Answers1

1

Use Remote Debugging - iOS and Safari

you can avoid using live reload and use safari debugging to see what's going wrong.

Safari can be used to debug an Ionic app on a connected iOS device. First, we need to enable Web Inspector on the connected device. Web Inspector can be found under Settings > Safari > Advanced. Next, head over to the Safari on your Mac and enable Show Develop menu in menu bar under Safari > Preferences > Advanced. The connected device should now appear in the Develop menu. From there, you can inspect it and use Safari's developer tools to debug your application!

Source: http://ionicframework.com/docs/cli/run.html

Shadi Shaaban
  • 1,670
  • 1
  • 10
  • 17
  • If I enable web inspection on both my iOS device and my mac. I would have to first serve my ionic application. Then I use the url I got on my device, correct? – Wakeme UpNow Jun 01 '16 at 16:48
  • no, you run your application on iOS device or emulator and use the remote debugging from safari, your device/emulator will show up as a connected device and you could debug it directly. – Shadi Shaaban Jun 01 '16 at 16:50
  • Oh, I see. Thank you – Wakeme UpNow Jun 01 '16 at 17:02