-
Notifications
You must be signed in to change notification settings - Fork 0
/
documentation.txt
105 lines (93 loc) · 6.96 KB
/
documentation.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
Assuming $PROJECT is the root of the project folder.
I was working on Ubuntu 14.04, windows experience may differ.
Focus was set on Android since iOS can only be developed on OSX machine. Include info about iOS where possible.
Building for Android.
1. Install Android SDK. (https://developer.android.com/sdk/index.html#Other) (https://spring.io/guides/gs/android/)
a. Set ANDROID_HOME environmental variable to SDK folder.
b. Add $ANDROID_HOME/tools:$ANDROID_HOME/platform-tools to $PATH
2. Install Java JDK. (http://www.oracle.com/technetwork/java/javase/downloads/index.html) (http://docs.oracle.com/cd/E19182-01/820-7851/inst_cli_jdk_javhome_t/index.html)
a. Set JAVA_HOME environmental variable to JDK folder.
b. Add $JAVA_HOME/bin to $PATH
3. In $PROJECT run: ionic platform add android
4. In $PROJECT run: ionic build android (From now on, this is the only thing required to build the project)
This will produce an .apk file: $PROJECT/platforms/android/build/outputs/apk/android-debug.apk
This .apk file can be uploaded to any android device and installed.
I reccommend using "ES File Explorer" to locate the .apk file on the mobile file system and install.
Making phone calls from app.
1. In $PROJECT run: ionic plugin add cordova-plugin-whitelist
2. Add to $PROJECT/config.xml
a. <access origin="tel:*" launch-external="yes" /> (http://forum.ionicframework.com/t/making-phone-call-from-app-href-tel-123/1968)
b. <allow-intent href="tel:*" /> (https://github.com/apache/cordova-plugin-whitelist)
3. Add links to the project: <a href="tel:+354-772-0105">Call Me!</a>
The reason why you need to do both access origin and allow-intent is because there are different implementations in different versions of android.
The earlier ones use access origin while the later versions use allow-intent.
Sending emails from app.
1. In $PROJECT run: ionic plugin add cordova-plugin-whitelist
2. Add to $PROJECT/config.xml
a. <access origin="mailto:*" launch-external="yes" /> (http://forum.ionicframework.com/t/making-phone-call-from-app-href-tel-123/1968)
b. <allow-intent href="mailto:*" /> (https://github.com/apache/cordova-plugin-whitelist)
3. Add links to the project: <a href="mailto:[email protected]">Mail Me!</a>
The reason why you need to do both access origin and allow-intent is because there are different implementations in different versions of android.
The earlier ones use access origin while the later versions use allow-intent.
The Process of Push Notifications: (http://cfile29.uf.tistory.com/image/161B1A34509CC4691E096B)
1. The mobile device contacts the messaging service and registers. This tells the messaging service that the device is ready to receive notifications.
2. The messaging service answers with a device token.
3. The mobile device contacts the backend servers and gives it user ID and device token. The user ID is something unique to us, so we can lookup the device tokens.
4. When the server needs to send a notification to the mobile device, it sends a push notification, containing the device token, to the messaging service.
5. The messaging service sends the notification to the mobile device. There it can either be handled in code or automatically spawns a notification.
a. When the user is engaged with the app, it is smoother to have an in-app popup instead of the default notification.
b. If the app is not registered or the mobile device is not listening. The messaging service will store the notification until it expires or deliver the notification as soon as it is able.
Enable Push Notifications. (https://azure.microsoft.com/en-us/documentation/articles/notification-hubs-overview/)
1. In $Project run:
a. ionic plugin add https://github.com/phonegap-build/PushPlugin
b. ionic plugin add https://github.com/katzer/cordova-plugin-local-notifications (this is not the official repo but at the time of this writing, the official repo is broken.)
i. See https://github.com/katzer/cordova-plugin-local-notifications/issues/426
2. Add Google Cloud Messaging to project: (https://azure.microsoft.com/en-us/documentation/articles/notification-hubs-android-get-started/)
a. Create a new project in https://console.developers.google.com
b. Enable Cloud Messaging for Android under APIs & Auth > APIs > Mobile APIs
c. Create API key for the project:
i. Create new Public API access Key under APIs & Auth > Credentials
ii. Press Server Key > Leave the box empty and press Create
d. Add GCM API key to project:
i. in $PROJECT run: ionic push --google-api-key [API key] (looks something like AIzaSyDw7xT23O4npbZBK5smtkAtE60G0t6fnlA)
3. Add code to angular.run function in app.js (Code can be seen in https://github.com/Flati/deploy-tutorial)
$ionicPlatformready(function () {
$ionicPush.register({ // This registers the device with the GCM servers and tells it the device is ready to receive push notifications (step 1).
senderID: '[PROJECT NUMBER]' // Looks something like: 902626345902 can be seen in https://console.developers.google.com
}).then(function(success) {
alert(success); // This returns if the register was successful.
}, function(error) {
alert(error); // This returns if the register was unsuccessful.
});
$rootScope.$on('$cordovaPush:tokenReceived', function(event, data) { // This returns the token for the device (step 2). It will never change on the device, unless you uninstall and reinstall the app.
alert('Got token' + data.token + data.platform);
// This is where you'd put the logic to register the user and token on your server side (step 3).
});
});
4. Formatting a push notification (http://docs.ionic.io/v1.0/docs/push-sending-push)
{
"tokens": ["TOKENS", "GO", "HERE"],
"notification": {
"alert": "Message goes here",
"ios": {
"priority": 10,
"badge": 2,
"sound": "ping.aiff",
"expiry": 1423238641, // Seconds since Epoch. Can be set to zero for a "1-attempt" notification, it's either delivered immediately, or not at all.
"contentAvailable": true,
"payload": { // Payload includes parameters that are sent to the app when the notification is clicked. This can be used to open a specific page or contact.
"$state": "app.contacts",
"$stateParams": "{\"id\": 36}" // I have no idea why this must be a string, and can't be an object.
}
},
"android": {
"collapseKey": "foo",
"delayWhileIdle": true,
"timeToLive": 300, // Time in seconds the message will be stored by GCM. Can be set to zero for a "1-attempt" notification, it's either delivered immediately, or not at all.
"payload": { // Payload includes parameters that are sent to the app when the notification is clicked. This can be used to open a specific page or contact.
"$state": "app.contacts",
"$stateParams": "{\"id\": 36}" // I have no idea why this must be a string, and can't be an object.
}
}
}
}