diff --git a/ios/App/App/Info.plist b/ios/App/App/Info.plist index 977135a..09839de 100644 --- a/ios/App/App/Info.plist +++ b/ios/App/App/Info.plist @@ -22,9 +22,18 @@ $(CURRENT_PROJECT_VERSION) LSRequiresIPhoneOS + NSLocationAlwaysAndWhenInUseUsageDescription + We need to enable geotagging to send you notifications and messages based on your location, so you will get the relevant ones only + NSLocationAlwaysUsageDescription + We need to enable geotagging to send you notifications and messages based on your location, so you will get the relevant ones only + NSLocationUsageDescription + We need to enable geotagging to send you notifications and messages based on your location, so you will get the relevant ones only + NSLocationWhenInUseUsageDescription + We need to enable geotagging to send you notifications and messages based on your location, so you will get the relevant ones only UIBackgroundModes remote-notification + location UILaunchStoryboardName LaunchScreen diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 0f9fb66..d37f84a 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,5 +1,4 @@ import { Component } from '@angular/core'; -import OneSignal from 'onesignal-cordova-plugin'; @Component({ selector: 'app-root', @@ -13,51 +12,6 @@ export class AppComponent { // Call this function when your app starts OneSignalInit(): void { - - // https://documentation.onesignal.com/docs/mobile-sdk - alert('OneSignalInit'); - - // 0 = None, 1 = Fatal, 2 = Errors, 3 = Warnings, 4 = Info, 5 = Debug, 6 = Verbose - // Uncomment to set OneSignal device logging to VERBOSE - OneSignal.Debug.setLogLevel(6); - - // 0 = None, 1 = Fatal, 2 = Errors, 3 = Warnings, 4 = Info, 5 = Debug, 6 = Verbose - // Uncomment to set OneSignal visual logging to VERBOSE - //OneSignal.Debug.setAlertLevel(6); - OneSignal.Debug.setAlertLevel(4); - - // NOTE: Update the init value below with your OneSignal AppId. - OneSignal.init("13755f98-ec69-45fd-a2f1-d2166afcaa51"); - - // Location permissions enable geotagging in the OneSignal dashboard to send notifications to users based on their location - OneSignal.Location.setShared(false); - - let myClickListener = async function(event) { - let notificationData = JSON.stringify(event); - alert("CLICKED: " + notificationData); - console.log('notificationOpenedCallback: ' + JSON.stringify(notificationData)); - - }; - OneSignal.Notifications.addEventListener("click", myClickListener); - - // Set a handler to run before displaying a notification while the app is in focus. - let myForegroundWillDisplayListener = async function(event) { - let notificationData = JSON.stringify(event); - alert("RECEIVED: " + notificationData); - console.log('foregroundWillDisplayCallback : ' + JSON.stringify(notificationData)); - - /// Display Notification, preventDefault to not display - event.preventDefault(); - - // Use notification.display() to display the notification after some async work - //event.notification.display(); - }; - OneSignal.Notifications.addEventListener('foregroundWillDisplay', myForegroundWillDisplayListener); - - // Prompts the user for notification permissions. - // * Since this shows a generic native prompt, we recommend instead using an In-App Message to prompt for notification permission (See step 7) to better communicate to your users what notifications they will get. - OneSignal.Notifications.requestPermission(function(accepted) { - console.log("User accepted notifications: " + accepted); - }); + console.log('Moved to home'); } } diff --git a/src/app/pages/home/home.page.ts b/src/app/pages/home/home.page.ts index d6b9b5e..a0969be 100644 --- a/src/app/pages/home/home.page.ts +++ b/src/app/pages/home/home.page.ts @@ -3,7 +3,7 @@ import { Router } from '@angular/router'; import { SessionDataProviderService } from 'src/app/store/session-data-provider.service'; import { BlogDataService } from 'src/app/store/blog-data.service'; import { WrenchService } from 'src/app/services/wrench.service'; - +import { OnesignalService } from 'src/app/services/onesignal.service'; @Component({ selector: 'app-home', @@ -20,6 +20,7 @@ export class HomePage implements OnInit { private router: Router, public sessionDataProviderService: SessionDataProviderService, private wrenchService: WrenchService, + private onesignalService: OnesignalService, public blogDataService: BlogDataService ) { this.firstname = this.sessionDataProviderService.firstname; @@ -34,6 +35,7 @@ export class HomePage implements OnInit { // this.getBannersData(); console.log("BLOG HOME 002->", this.blogDataService.blogData); // this.firstname = this.sessionDataProviderService.firstname; + this.onesignalService.Init(this.sessionDataProviderService.member_uid); } ionViewDidEnter(){ diff --git a/src/app/services/onesignal.service.spec.ts b/src/app/services/onesignal.service.spec.ts new file mode 100644 index 0000000..b5858e2 --- /dev/null +++ b/src/app/services/onesignal.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { OnesignalService } from './onesignal.service'; + +describe('OnesignalService', () => { + let service: OnesignalService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(OnesignalService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/services/onesignal.service.ts b/src/app/services/onesignal.service.ts new file mode 100644 index 0000000..5df82e3 --- /dev/null +++ b/src/app/services/onesignal.service.ts @@ -0,0 +1,96 @@ +import { HttpClient } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs'; +//import 'rxjs/add/operator/map'; +import { environment } from 'src/environments/environment'; +import { SessionDataProviderService } from '../store/session-data-provider.service'; +import {Router} from "@angular/router"; +import OneSignal from 'onesignal-cordova-plugin'; + +@Injectable({ + providedIn: 'root' +}) +export class OnesignalService { + AppId; + + constructor(private http: HttpClient, + private router: Router, + public sessionDataProviderService :SessionDataProviderService) { + // this is test + this.AppId = '13755f98-ec69-45fd-a2f1-d2166afcaa51'; + } + + // Call this function when your app starts + Init(member_uid): void { + + // https://documentation.onesignal.com/docs/mobile-sdk + alert('OneSignalInit'); + + // 0 = None, 1 = Fatal, 2 = Errors, 3 = Warnings, 4 = Info, 5 = Debug, 6 = Verbose + // Uncomment to set OneSignal device logging to VERBOSE + OneSignal.Debug.setLogLevel(6); + + // 0 = None, 1 = Fatal, 2 = Errors, 3 = Warnings, 4 = Info, 5 = Debug, 6 = Verbose + // Uncomment to set OneSignal visual logging to VERBOSE + //OneSignal.Debug.setAlertLevel(6); + OneSignal.Debug.setAlertLevel(4); + + // NOTE: Update the init value below with your OneSignal AppId. + OneSignal.init(this.AppId); + + // Location permissions enable geotagging in the OneSignal dashboard to send notifications to users based on their location + OneSignal.Location.setShared(true); + + let myClickListener = async function(event) { + let notificationData = JSON.stringify(event); + alert("CLICKED: " + notificationData); + console.log('notificationOpenedCallback: ' + JSON.stringify(notificationData)); + + }; + OneSignal.Notifications.addEventListener("click", myClickListener); + + // Set a handler to run before displaying a notification while the app is in focus. + let myForegroundWillDisplayListener = async function(event) { + let notificationData = JSON.stringify(event); + alert("RECEIVED: " + notificationData); + console.log('foregroundWillDisplayCallback : ' + JSON.stringify(notificationData)); + + /// Display Notification, preventDefault to not display + event.preventDefault(); + + // Use notification.display() to display the notification after some async work + //event.notification.display(); + }; + OneSignal.Notifications.addEventListener('foregroundWillDisplay', myForegroundWillDisplayListener); + + // Prompts the user for notification permissions. + // * Since this shows a generic native prompt, we recommend instead using an In-App Message to prompt for notification permission (See step 7) to better communicate to your users what notifications they will get. + OneSignal.Notifications.requestPermission(function(accepted) { + console.log("User accepted notifications: " + accepted); + }); + + //OneSignal.User.addAlias("external_id", member_uid); + OneSignal.login(member_uid); + // OneSignal.getUser().addEmail(emailAddress, emailAuthHash); + // Auth hashes are expected to be a HMAC on a SHA-256 of the OneSignal REST API Key and the + // + + + + app/build.gradle + + dependencies { + ... + implementation 'com.google.android.gms:play-services-location:YOUR_PLAY_SERVICES_VERSION' + } + */ + } +} \ No newline at end of file