티스토리 뷰
Adroid
1. Nuget 설치
Xamarin.GooglePlayServices.Base
Xamarin.Firebase.Messaging
Xamarin.Google.Android.DataTransport.TransportRuntime
Xamarin.Google.Dagger
Xamrin.Azure.NotificationHubs.Android
Xamarin.Andoidx.Annotation
Ios
Entitlements.plist 더블클릭 > 하단 자격에서 Push Notifications 사용 체크!!
새로운 클래스를 만들고 아래 UserNotificationcenterDelegate 를 작성한다.
internal class UserNotificationCenterDelegate : UNUserNotificationCenterDelegate
{public UserNotificationCenterDelegate() { } //This will be called when the notification is received when the app is in Foreground public override void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action<UNNotificationPresentationOptions> completionHandler) { // var RequestCode = notification.Request.Content.UserInfo["Code"].ToString(); completionHandler(UNNotificationPresentationOptions.Alert); Console.WriteLine("user WillPresentNotification"); } public override void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler) { if (response.IsDefaultAction) { // var Notify = response.Notification.Request.Content; // var Code = Notify.UserInfo["Code"]; } // Complete handling the notification. completionHandler();
Console.WriteLine("user Noti delegate");
}
}
Appdelegate.cs에서
[Register("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate, IUNUserNotificationCenterDelegate, IMessagingDelegate
{
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{LoadApplication(new App()); RegisterForRemoteNotifications();
Firebase.Core.App.Configure();
UIApplication.SharedApplication.RegisterForRemoteNotifications();
if (UNUserNotificationCenter.Current != null)
{
UNUserNotificationCenter.Current.Delegate = new UserNotificationCenterDelegate();
}
Messaging.SharedInstance.Delegate = this;
return base.FinishedLaunching(app, options);
}
}
private void RegisterForRemoteNotifications()
{
// Register your app for remote notifications.
if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
{
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.Current.Delegate = this;
var authOptions = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound;
UNUserNotificationCenter.Current.RequestAuthorization(authOptions, async (granted, error) =>
{
Console.WriteLine(granted);
await System.Threading.Tasks.Task.Delay(500);
//await AcessPermissionsAsync();
});
}
else
{
// iOS 9 or before
var allNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound;
var settings = UIUserNotificationSettings.GetSettingsForTypes(allNotificationTypes, null);
UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
}
UIApplication.SharedApplication.RegisterForRemoteNotifications();
// Messaging.SharedInstance.ShouldEstablishDirectChannel = true;
Console.WriteLine("here1");
}
public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
{
Messaging.SharedInstance.ApnsToken = deviceToken;
//base.RegisteredForRemoteNotifications(application, deviceToken);
Console.WriteLine("here2");
}
public override void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
{
// base.FailedToRegisterForRemoteNotifications(application, error);
Console.WriteLine("here3");
}
//public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
//{
// completionHandler(UIBackgroundFetchResult.NewData);
// Console.WriteLine("here4");
//}
[Export("messaging:didReceiveRegistrationToken:")]
public void DidReceiveRegistrationToken(Messaging messaging, string fcmToken)
{
// Messaging.SharedInstance.FcmToken.UpdateDeviceId();
// TODO: If necessary send token to application server.
// Note: This callback is fired at each app startup and whenever a new token is generated.
// Console.WriteLine("here5:" + fcmToken);
try
{
if (DeviceInfo.DeviceType != DeviceType.Virtual)
{
string firebase_text = SecureStorage.GetAsync("FcmToken").Result;
if (firebase_text != null)
{
SecureStorage.Remove("FcmToken");
}
SecureStorage.SetAsync("FcmToken", fcmToken.ToString());
}
}
catch (Exception ex)
{
Console.WriteLine("//////////////:" + ex.Message);
}
}
//AppDelegate.cs
[Export("application:didReceiveRemoteNotification:fetchCompletionHandler:")]
public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
{
Console.WriteLine("here4");
// ProcessNotification(userInfo, application.ApplicationState == UIApplicationState.Active);
}
}
2021.04.04 ios push 잘 들어온다.
(정말 온갖 자료 미친듯이 찾아다녔다.ㅜㅜ)
*** 여기참고>> https://techartly.com/fcm-push-notification-ios/
https://github.com/MicrosoftDocs/azure-docs/issues/58976
https://forums.xamarin.com/discussion/184475/xamarin-forms-ios-not-showing-fcm-push-notification-on-ios-physical-device
https://medium.com/@acanales199/this-worked-for-me-with-version-4-3-0-firebase-cloudmessaging-a1def91263b7
https://forums.xamarin.com/discussion/159477/xamarin-forms-push-notification-is-not-receiving-to-ios-device
https://github.com/firebase/firebase-ios-sdk/issues/4996
참고자료.
UNNotificationPresentationOptions.Alert);;)
Android 개발자 활성화
1. 설정> 휴대전화 정보 > 소프트웨어 정보 > 빌드번호 7회 클릭
2. 개발자 옵션 USB디버깅 허용
<참고>
http client 기술자료
'Xamarin' 카테고리의 다른 글
Xamarin.Forms Android PhoneAuthProvider.Instance.VerifyPhoneNumber deprecated Resolve (0) | 2021.04.08 |
---|---|
Xamarin.Forms Ios URL Schemes for Firebase Phone Auth reCAPTCHA (0) | 2021.04.05 |
Xamarin.Forms image download from Server image API (0) | 2021.03.31 |
Xamarin.Android WebView에서 페이지 안보일때. (0) | 2021.03.31 |
Xamarin CollectionView Binding Visible not shown (0) | 2021.03.23 |
- Total
- Today
- Yesterday
- Xamarin reCAPTCHA
- Xamarin Firebase Phone Auth
- GetCellContent CheckBox Value
- Xamarin.Ios Firebase Phone SMS OTP Send
- WPF Datagrid Cell Value Change
- Xamarin.Forms
- Xamarin.Ios Firebase Phone Auth
- Label Text LineBreak in Xaml
- Microcharts
- ssl_client_socket_impl.cc
- 암호 마스터키
- FileStream Add Byte
- 서버 수준의 URN 필터
- 연산자 뒤에 피연산자가 없습니다.
- Xamarin SMS OTP Send
- c# Encrypt / Decrypt
- Entry '' has empty native path
- WPF Scrollviewer in ScrollViwer
- Windows IIS FTP 디렉토리 목록 오류
- Xamarin Firebase Phone User Add
- WPF Textbox
- Embeded 한글Font적용
- ClickOnce 인증서 인증기간 변경
- WPF Excel Export Microsoft.Office.Interop 성능향상(열 기준으로 복사)
- Xamarin.Ios Firebase Phone User Add
- SkiaSharp
- Linux SSH Multi Computer Join
- C# LINQ Left join
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |