How to send push notification from one user to another in Ionic?
I want to send push notification from one user to another in my Ionic application. Suppose, User1 likes a pic of User2 then User2 will receive "User1 liked your pic" notification. How can I achieve this using FCM, OneSignal or other?
See also questions close to this topic
-
Firebase Hosting - how to creating a publicly accessible folder?
I am using Firebase Hosting to host my React application. I need to create a publicly accessible folder on my website and upload a file to it, like this: https://www.example.com/.well-known/assetlinks.json. How can I accomplish this?
-
Ignoring exception from a finished function
I keep getting this error when this function executes.
Ignoring exception from a finished function
What I'm I missing?
exports = module.exports = functions.database.ref('/cards/{userId}/{id}') .onCreate((snap, context) => { const token = snap.val().token; const userId = context.params.userId; const stripeRef = admin.database().ref('/stripe').child(userId); return stripeRef.once('value').then(function(snapshot) { let accountId = snapshot.val().accountId; return stripe.accounts.createExternalAccount( accountId, { external_account: token }, function(err, card) { snap.ref.child('cardId').set(card.id); }); }); });
-
Implement distributed counter on Firebase
I am trying to implement a three shard distributed counter at
/counters/{i}
.Initially, I want to check if the document/collection exists, if it doesn't it needs to be recreated, with userCount set to 0.
If it does exist, then the above step is skipped, and userCount is incremented by one.
How do I go about doing this? This is my code so far:
incrementUserCount() { // First check to see if user exists for (let i = 0; i < environment.numberOfShards; i++) { const newShardReference = this.afs.firestore.collection('counters').doc(i.toString()); this.afs.firestore.batch().set(newShardReference, { userCount: 0 }); } this.afs.firestore.batch().commit(); // Steps to increment user count // const shardId = Math.floor(Math.random() * environment.numberOfShards).toString(); // const shardReference = this.afs.firestore.collection('counters').doc(shardId); // return this.afs.firestore.runTransaction(t => { // return t.get(shardReference).then(doc => { // const newCount = doc.data().count + 1; // t.update(shardReference, { count: newCount }); // }); // }); }
-
I want to passing id (stored in firestore) from page to another page in ionic4 App
i want to passing ID that i stored it in Firestore database from page to another page in my Ionic4 App
i have news app that i retrieved the contents from firestore and i want when i click on the news it must show the details in details page my code in briefly :
news.page.html
<ion-content padding> <ion-item *ngFor=" let count of data"> <h5>{{count.title}}<ion-button (click)="goToDetail()">click for details</ion-button> <img src="{{count.image}}"> </h5> </ion-item>
news.page.ts
export class FilmsPage implements OnInit { data: any; constructor(public db: AngularFirestore, private router: Router) { } ngOnInit() { this.getAllPosts().subscribe((data) => { this.data = data; console.log(data); }); } getAllPosts(): Observable<any> { return this.db.collection<any>('123').valueChanges (); } goToDetail() { this.router.navigateByUrl('/details/{{count.id}}'); } }
details.page.ts
export class DetailsPage implements OnInit { id: string; constructor(private router: ActivatedRoute, private afs: AngularFirestore) { } ngOnInit() { this.id = this.router.snapshot.paramMap.get('id'); console.log(this.id); } }
details.page.html
<ion-content padding> {{id}} </ion-content>
but when i run this code its just showed {{count.id}} in details.page.html .. why??? can somone solve this probllem please
-
'MonoTypeOperatorFunction<...>' is not assignable to parameter of type 'OperatorFunction<..>
I'm using Ionic 4.10.2 and trying to get an authentication service written using an example in a tutorial I found (https://www.techiediaries.com/ionic-jwt-authentication-httpclient/ except I'm using a java REST server on the back-end)
The error I'm getting is:
[ng] ERROR in src/app/auth/auth.service.ts(40,17): error TS2345: Argument of type 'MonoTypeOperatorFunction<AuthResponse>' is not assignable to parameter of type 'OperatorFunction<HttpResponse<AuthResponse>, AuthResponse>'. [ng] Types of parameters 'source' and 'source' are incompatible. [ng] Type 'Observable<HttpResponse<AuthResponse>>' is not assignable to type 'Observable<AuthResponse>'. [ng] Type 'HttpResponse<AuthResponse>' is not assignable to type 'AuthResponse'. [ng] Property 'user' is missing in type 'HttpResponse<AuthResponse>'. [ng] src/app/web-services/test-page/test-page.page.ts(4,40): error TS2307: Cannot find module './test-rest-service.servi ce'. [ng] src/app/web-services/test-rest-service.service.ts(42,30): error TS2304: Cannot find name 'apiUrl'. [ng]
All of the answers I found online say this could be due to multiple versions of rxjs in the project. But I only see one:
PS C:\projectFolder> npm list rxjs MobileAppTemplate@0.0.1 C:\projectFolder +-- @angular-devkit/architect@0.12.4 | `-- rxjs@6.3.3 deduped +-- @angular-devkit/build-angular@0.12.4 | +-- @angular-devkit/build-webpack@0.12.4 | | `-- rxjs@6.3.3 deduped | +-- @ngtools/webpack@7.2.4 | | `-- rxjs@6.3.3 deduped | `-- rxjs@6.3.3 deduped +-- @angular-devkit/core@7.2.4 | `-- rxjs@6.3.3 deduped +-- @angular-devkit/schematics@7.2.4 | `-- rxjs@6.3.3 deduped +-- @angular/cli@7.2.4 | +-- @schematics/update@0.12.4 | | `-- rxjs@6.3.3 deduped | `-- inquirer@6.2.1 | `-- rxjs@6.3.3 deduped `-- rxjs@6.3.3
Here's the code:
import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { tap } from 'rxjs/operators'; import { Observable, BehaviorSubject } from 'rxjs'; import { Storage } from '@ionic/storage'; import { User } from './user'; import { AuthResponse } from './auth-response'; @Injectable({ providedIn: 'root' }) export class AuthService { AUTH_SERVER_ADDRESS: string = "http://SERVERIP:8080/WebServicesTemplate"; REGISTRATION_URL: string = this.AUTH_SERVER_ADDRESS + "/user/register"; LOGIN_URL: string = this.AUTH_SERVER_ADDRESS + "/login"; ACCESS_TOKEN_NAME: string = "ACCESS_TOKEN"; ACCESS_TOKEN_EXPIRATION_TIME: string = "EXPIRES_IN"; authSubject = new BehaviorSubject(false); constructor(private httpClient: HttpClient, private storage: Storage) { } register(user: User): Observable<AuthResponse> { return this.httpClient.post<AuthResponse>(`${this.REGISTRATION_URL}`, user) .pipe( tap(async (response: AuthResponse) => { if(response.user) { await this.storage.set(this.ACCESS_TOKEN_NAME, response.user.accessToken); await this.storage.set(this.ACCESS_TOKEN_EXPIRATION_TIME, response.user.expiresIn); this.authSubject.next(true); } }) ); }// end register(.) login(user: User): Observable<AuthResponse> { return this.httpClient.post<AuthResponse>(`${this.LOGIN_URL}`, user, {observe: "response"}) .pipe( tap(async (response: AuthResponse ) => { if(response.user) { await this.storage.set(this.ACCESS_TOKEN_NAME, response.user.accessToken); await this.storage.set(this.ACCESS_TOKEN_EXPIRATION_TIME, response.user.expiresIn); this.authSubject.next(true); } }) ); }// end login(.) async logout() { await this.storage.remove(this.ACCESS_TOKEN_NAME); await this.storage.remove(this.ACCESS_TOKEN_EXPIRATION_TIME); this.authSubject.next(false); } isLoggedIn() { return this.authSubject.asObservable(); } }
What can I do to solve this?
-
I want to achieve, Hierarchical Structure using self calling component, does it need to be declared in the AppModule?
I am actually having a bit of a trouble in achieving Hierarchical Structure using selector. The app is currently in lazy loading structure. The component I created is a template for a parent. I successfully display the data in first go (Hierarchy 1, Hierarchy 2) because these are head. But in the second, (Hierarchy 1.1, Hierarchy 1.2), crashes the app and there, I called the selector itself. Do I need to make this as a page or would it be okay as a component to call the selector?
EXPECTED RESULTS:
Hierarchy 1
- Hierarchy 1.1
- Hierarchy 1.2
- Hierarchy 1.2.1
Hierarchy 2
- Hierarchy 2.1
Hierarchy 3
-
Picture in picture mode in ionic
I have created a WhatsApp like app in ionic which allows the user to chat, video call and share files. I would like to add the feature where the user can minimize the video calling screen to a corner of the screen and do the regular chat. Like we can do in WhatsApp. My question is, is it possible to create a picture in picture mode in the ionic app? Any guidance would be of great help.
-
How to register onesignal with curl?
I dont know why the js is very buggdy in terms of registration with tags. With curl i get it done immediatly seebelow
$fields = array( 'app_id' => "xxxxxxxxxxxxxxxxxxxxxxxxxx", 'language' => "nl", 'identifier' => "xxxxxxxxxxxxxxxxxxxxxxxxxxxx", 'device_type' => "5", 'device_model' => getOs($_SERVER['HTTP_USER_AGENT']), 'notification_types' => "1", 'tags' => array("email" => $rr['emailadres']) ); $fields = json_encode($fields); //print("\nJSON sent:\n"); //print($fields); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/players"); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); $response = curl_exec($ch); curl_close($ch); $return["allresponses"] = $response; $return = json_encode( $return);
Well, now i want to send push notifications with curl, but when i do with this code:
public function sendPush($text,$title,$email,$url,$imgUrl) { //echo $text.$title.'-'.$email.'-'.$url.'-'.$imgUrl; ini_set('display_errors',0); error_reporting(E_ALL); $content = array( "nl" => ''.$text.'' ); $filters = array( array("field" => "tag", "key" => "email","relation" => "=", "value" => $email), ); $fields = array( 'app_id' => "676e190e-4c85-4de6-9f8c-84dec6fca383", 'included_segments' => array('All'), 'headings' => array("nl" => "".$title.""), 'content_available' => array(true), 'contents' => $content, 'url' => $url, 'filters' => array(array("field" => "tag","key" => "email", "value" => "".$email."")) ); $fields = json_encode($fields); // print("\nJSON sent:\n"); //print($fields); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications"); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8', 'Authorization: Basic OTE3YjliZGYtMmVmNi00NjAyLTgxNmItNDNkOTY2ZWM2OTY2')); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); $response = curl_exec($ch); curl_close($ch); return $response; ini_set('display_errors',0); error_reporting(E_ALL); }
Then i see in the onesignal log by status: NO RECIPIENTS ?? The email tag exist, so wy wuld it be send?
Could i send it straight to a player id ?
-
onesignal set url when notification received
I'm using webpush notification. (not mobile).
I have been struggling about this for a very long time and I'd be so happy if you'd just try to help me a little bit. Thank you guys really so much.
I send notification from php back-end api to front-end. Onesignal says that you must pass url parameter from back-end api. Turned out I can't do that, because if I do that, then back-end api has to know my front-end urls, which I didn't want.
Here is how I want: I'd pass some parameters id=2&name="giorgi" from my back-end and when I'd recieve notification on front-end , I'd set the url there . When user'd click on the notification, he would go to that url.
OneSignal.on('notificationDisplay', function(event) { event.url ="anotherurl/change"; console.warn('OneSignal notification displayed:', event); });
I tried this, but
event.url doesn't change it
. -
iOS Application BadgeCount is keeping count despite making badge count to zero. I am sending push notifications with OneSignal
I am sending a push notification so the badge count is 1, then on AppDelegate applicationDidBecomeActive I do
[UIApplication sharedApplication].applicationIconBadgeNumber = -1;
, so the badge hides, but after a new push notification arrives the badge count continues to 2, and so the number gets extremely high.I also tried
UIApplication sharedApplication].applicationIconBadgeNumber = 0;
andapplication.applicationIconBadgeNumber = -1;
I am not doing anything on the server side to manage the badge count, so what could it be causing me this trouble?