“The UIApplicationDelegate in the iPhone App never called reply() ” - Xamarin - ios

I am trying to build watch kit application and connect it with my iOS app, using xamarin framework.In HandleWatchKitExtensionRequest I use MarketRequestHandler class in order to bring data from API and display it on watchkit.
My Error is:
"The UIApplicationDelegate in the iPhone App never called reply() in -[UIApplicationDelegate application:handleWatchKitExtensionRequest:reply:]}
Class: {ObjCRuntime.Class}
ClassHandle (Foundation.NSError): 0xf09c10
ClassHandle (Foundation.NSObject): 0xf09c10
Code: 2
DebugDescription: "Error Domain=com.apple.watchkit.errors Code=2 \"The UIApplicationDelegate in the iPhone App never called reply() in -[UIApplicationDelegate application:handleWatchKitExtensionRequest:reply:]\" UserInfo={NSLocalizedDescription=The UIApplicationDelegate in the iPhone App never called reply() in -[UIApplicationDelegate application:handleWatchKitExtensionRequest:reply:]}"
This is my code:
public override void HandleWatchKitExtensionRequest
(UIApplication application, NSDictionary userInfo, Action<NSDictionary> reply) {
var json = new JsonParams ();
var id="";
nint taskID = UIApplication.SharedApplication.BeginBackgroundTask (() => {
});
new Task (() =>{
MarketRequestHandler mrk = new MarketRequestHandler();
json.ckeys = new string[]{"P"};
json.ids = new string[0];
json.fields = new string[]{
"LastDealTime",
"LastDealDate"
};
json.index = 0;
json.count = 300;
var jsonStr = JsonConvert.SerializeObject (json);
mrk.HandleRequest("market.get",jsonStr, (cb) =>{
id = json.ids[0];
reply (new NSDictionary (
"index", NSNumber.FromInt32 ((int)json.index),
"count", NSNumber.FromInt32((int)json.count),
"rzf", new NSString(id)
));
});
UIApplication.SharedApplication.EndBackgroundTask(taskID);
}).Start ();
}
Watch interface
public override void Awake (NSObject context)
{
// Configure interface objects here.
base.Awake (context);
Console.WriteLine ("{0} awake with context", this);
WKInterfaceController.OpenParentApplication (new NSDictionary (), (replyInfo, error) => {
if(error != null) {
Console.WriteLine (error);
return;
}
Console.WriteLine ("parent app responded");
// do something with replyInfo[] dictionary
Label.SetText ( replyInfo.Keys[0].ToString() + " " + replyInfo.Values[0].ToString());
label2.SetText(replyInfo.Keys[1].ToString() + " " + replyInfo.Values[1].ToString());
label3.SetText(replyInfo.Keys[2].ToString() + " " + replyInfo.Values[2].ToString());
});
}

Looking at your code, I would guess that id = json.ids[0]; throws an IndexOutOfRangeException since previously you set it to an empty array. That's why reply is never called. Perhaps you wanted to use cb instead of json in the callback handler.

Related

xamarin push notification ios Page navigation not working when push notification click

I have azure push notification in Xamarin forms. when push notification received I need to open a page in my application. Its working fine in android. In iOS its not working when app is open. When app is in the background its working find in iOS.
This is my App Delegate code
public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo,
Action<UIBackgroundFetchResult> completionHandler)
{
try
{
UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
NSError error;
NSData notification = NSJsonSerialization.Serialize(userInfo["action"], NSJsonWritingOptions.PrettyPrinted, out error);
string notificationString = NSString.FromData(notification, NSStringEncoding.UTF8).ToString();
var NotificationObj = JsonConvert.DeserializeObject<NotificationData>(notificationString);
NotificationService.pushPageName = NotificationObj.Notification[0].PageName.ToString();
NotificationService.pushAppName = NotificationObj.AppName.ToString();
NotificationService.OpenPages = NotificationObj.Notification[0].OpenPage;
NotificationService.Notification = notificationString;
if (UIApplication.SharedApplication.ApplicationState.Equals(UIApplicationState.Active))
{
//App is in foreground. Act on it.
var application1 = new App(NotificationService.pushPageName, NotificationService.pushAppName, NotificationService.Notification);
LoadApplication(application1);
}
else
{
// var application1 = new App(NotificationService.pushPageName, NotificationService.pushAppName, NotificationService.Notification);
// LoadApplication(application1);
}
}
catch (Exception ex)
{
//LogInfo.ReportErrorInfo(ex.Message, ex.StackTrace, "AppDelegate-DidReceiveRemoteNotification");
}
}
after click push notification I need to open splash screen again.
This is App.cs Code
public App(string openPageName, string openAppName,string notification)
{
ServiceContainer.Resolve<IPushNotificationActionService>()
.ActionTriggered += NotificationActionTriggered;
InitMainPage(openPageName, openAppName, notification);
}
private void InitMainPage(string pageName,string appName,string notification)
{
ServiceContainer.Resolve<IPushNotificationActionService>()
.ActionTriggered += NotificationActionTriggered;
PushNotificationActionService.PushNotificationPageName = pageName ;
PushNotificationActionService.PushNotificationAppName = appName;
PushNotificationActionService.PushNotificationMessage = notification;
MainPage = new NavigationPage(new Splash(pageName));
}
All methods are calling and push notification data also loading correctly in iOS. But not navigating to Spalsh Screen. Anyone have an idea to resolve this please help.
If the app is running, we don't need to reload app with LoadApplication , we can directly send message to set MainPage in App.cs .
iOS
if (UIApplication.SharedApplication.ApplicationState.Equals(UIApplicationState.Active))
{
MessagingCenter.Send<object>(this,"Hi");
}
Forms
public App()
{
InitializeComponent();
MainPage = new MainPage();
MessagingCenter.Subscribe<object>(this, "Hi", (obj) => {
MainPage = new NavigationPage(new Splash(pageName));
});
}

Xamarin Firebase iOS not receiving FCM messages

I tried to implement Firebase push notifications and messages in my Xamarin Forms application. In Android it works fine, while in iOS I am receiving push notifications but I'm not receiving FCM data-only messages.
I am using Xamarin.Firebase.iOS.CloudMessaging package, and I followed this guide and this other one too.
This is my AppDelegate.cs code:
[Register("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate, IUNUserNotificationCenterDelegate, IMessagingDelegate
{
//
// This method is invoked when the application has loaded and is ready to run. In this
// method you should instantiate the window, load the UI into it and then make the window
// visible.
//
// You have 17 seconds to return from this method, or iOS will terminate your application.
//
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
Forms.SetFlags("Brush_Experimental");
Rg.Plugins.Popup.Popup.Init();
//Ascetic.Plugins.PopupDecorations.iOS.PrettyPopup.Init();
global::Xamarin.Forms.Forms.Init();
SfListViewRenderer.Init();
new Syncfusion.SfAutoComplete.XForms.iOS.SfAutoCompleteRenderer();
Syncfusion.XForms.iOS.TabView.SfTabViewRenderer.Init();
iOSMaterialFrameRenderer.Init();
LoadApplication(new App());
// Register your app for remote notifications.
configureFirebase();
var result = base.FinishedLaunching(app, options);
app.KeyWindow.TintColor = UIColor.White;
foreach (var fs in UIFont.FamilyNames.OrderBy(c => c).ToList())
{
Console.WriteLine(" * " + fs);
foreach (var f in UIFont.FontNamesForFamilyName(fs).OrderBy(c => c).ToList())
{
Console.WriteLine(" *-- " + f);
}
}
return result;
}
private void configureFirebase()
{
Firebase.Core.App.Configure();
if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
{
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.Current.Delegate = this;
// iOS 10 or later
var authOptions = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound;
UNUserNotificationCenter.Current.RequestAuthorization(authOptions, (granted, error) =>
{
});
// For iOS 10 data message (sent via FCM)
Messaging.SharedInstance.Delegate = this;
}
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();
}
//Firebase
[Export("messaging:didReceiveRegistrationToken:")]
public void DidReceiveRegistrationToken(Messaging messaging, string fcmToken)
{
Preferences.Set("tokenNotifica", fcmToken);
Console.WriteLine("\nValue: " + (fcmToken));
}
//APP IN BACKGROUND
public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
{
handleNotification(userInfo);
completionHandler(UIBackgroundFetchResult.NewData);
}
[Export("userNotificationCenter:willPresentNotification:withCompletionHandler:")]
public void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification,
Action<UNNotificationPresentationOptions> completionHandler)
{
handleNotification(notification.Request.Content.UserInfo);
completionHandler(UNNotificationPresentationOptions.Sound | UNNotificationPresentationOptions.Alert);
}
[Export("userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:")]
public void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action
completionHandler)
{
completionHandler();
NSDictionary userInfo = response.Notification.Request.Content.UserInfo;
try
{
var Data = userInfo[new NSString("gcm.notification.data")] as NSString;
if (Data != null && Data != "")
{
string[] tokens = Data.ToString().Split(',');
string Username = tokens[0];
string Password = tokens[1];
var Title = string.IsNullOrEmpty(response.Notification.Request.Content.Title) ? "No Notification available" : response.Notification.Request.Content.Title;
var Body = string.IsNullOrEmpty(response.Notification.Request.Content.Body) ? "No Message available" : response.Notification.Request.Content.Body;
}
}
catch (Exception)
{
}
}
[Export("messaging:didReceiveMessage:")]
public void DidReceiveMessage(Messaging messaging, RemoteMessage message)
{
handleNotification(message.AppData);
}
public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
{
Messaging.SharedInstance.ApnsToken = deviceToken;
}
public void ApplicationReceivedRemoteMessage(RemoteMessage remoteMessage)
{
;
}
}
The DidReceiveRegistrationToken method is called with the token. If I send a notification to that token the method DidReceiveRemoteNotification is called, and the notification is successfully shown by the device. But if I send a data-only message to that token, nothing is called.
I tried disabling swizzling, enabling it, reconfigure Firebase from scratch and delete and recreate certificates and provisioning profiles in the Apple Dev website, but nothing worked. Also, I think all is configured correctly since my app is receiving notifications.
I hope I gave enough information, I am struggling with this for weeks
EDIT
I use this function in php to send the data-only message to devices
function sendMessage($deviceKey, $data){
$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"project_id: ***",
"Authorization: key=***"
));
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, [
CURLOPT_URL => 'https://fcm.googleapis.com/fcm/send',
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_USERAGENT => 'Codular Sample cURL Request',
CURLOPT_POST => 1,
]);
$body = [
'to' => $deviceKey,
"data" => $data
];
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($body));
$res = json_decode(curl_exec($curl), true);
curl_close($curl);
return $res;
}
This function is equal to the function that send the notification, but the $body array doesn't contain a "notification" key.
What I would like to do is use the data payload of the message in the application without display the notification, and this works just fine in Android, but not in iOS.

FCM Xamarin.Forms, iOS background Notification doesnt show

Platform: iOS 10.2+
Xamarin Plugin: Firebase iOS cloud messaging https://components.xamarin.com/view/firebaseioscloudmessaging
Problem: When I send a notification from FireBase console or from my code calling FireBase. My iPhones don't receive the background notifications(as a bubble). But, if I had the application in foreground, I received the notification as a "DisplayAlert" from the function ApplicationReceivedRemoteMessage(RemoteMessage remoteMessage).
So, the device is registered on FCM, the device have the token, the device can receive the notifications, but the device didnt receive the notifications on background.
** In VisualStudio 2017 at .iOS project manifest I have the Background mode activated and the remote notifications activated too **
¿It's this a common issue? ¿Can I solve for working at my project?
Code of AppDelegate
[Register("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate, IUNUserNotificationCenterDelegate, IMessagingDelegate
{
protected SQLiteAsyncConnection conn;
//
// This method is invoked when the application has loaded and is ready to run. In this
// method you should instantiate the window, load the UI into it and then make the window
// visible.
//
// You have 17 seconds to return from this method, or iOS will terminate your application.
//
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
global::Xamarin.FormsMaps.Init();
CachedImageRenderer.Init();
LoadApplication(new App());
UITabBar.Appearance.SelectedImageTintColor = UIColor.FromRGB(139, 194, 77);
UINavigationBar.Appearance.TintColor = UIColor.FromRGB(139,194,77);
CrossVersionTracking.Current.Track();
// Firebase component initialize
Firebase.Analytics.App.Configure();
// Register your app for remote notifications.
if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
{
// iOS 10 or later
var authOptions = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound;
UNUserNotificationCenter.Current.RequestAuthorization(authOptions, (granted, error) => {
Console.WriteLine(granted);
});
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.Current.Delegate = this;
// For iOS 10 data message (sent via FCM)
Messaging.SharedInstance.RemoteMessageDelegate = this;
}
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();
Firebase.InstanceID.InstanceId.Notifications.ObserveTokenRefresh((sender, e) =>
{
newToken = Firebase.InstanceID.InstanceId.SharedInstance.Token;
//Conectamos con la base de datos.
database = new SQLiteClient();
conn = database.GetConnection();
usuario = null;
try
{
var task = Task.Run(async () =>
{
usuario = await conn.Table<Usuario>()
.FirstOrDefaultAsync();
});
task.Wait();
if (usuario != null)
{
usuario.token = newToken;
task = Task.Run(async () =>
{
await conn.InsertOrReplaceAsync(usuario);
});
task.Wait();
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("TOKEN ERROR\tNo se ha podido Guardar el Token" + ex.Message);
}
System.Diagnostics.Debug.WriteLine("TOKEN\t" + newToken);
connectFCM();
});
#endregion
return base.FinishedLaunching(app, options);
}
public override void DidEnterBackground(UIApplication uiApplication)
{
Messaging.SharedInstance.Disconnect();
Console.WriteLine("Disconnected from FCM");
}
public override void OnActivated(UIApplication uiApplication)
{
connectFCM();
base.OnActivated(uiApplication);
}
public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
{
#if DEBUG
Firebase.InstanceID.InstanceId.SharedInstance.SetApnsToken(deviceToken, Firebase.InstanceID.ApnsTokenType.Sandbox);
#endif
#if RELEASE
Firebase.InstanceID.InstanceId.SharedInstance.SetApnsToken(deviceToken, Firebase.InstanceID.ApnsTokenType.Prod);
#endif
}
// iOS 9 <=, fire when recieve notification foreground
public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
{
Messaging.SharedInstance.AppDidReceiveMessage(userInfo);
// Generate custom event
NSString[] keys = { new NSString("Event_type") };
NSObject[] values = { new NSString("Recieve_Notification") };
var parameters = NSDictionary<NSString, NSObject>.FromObjectsAndKeys(keys, values, keys.Length);
// Send custom event
Firebase.Analytics.Analytics.LogEvent("CustomEvent", parameters);
if (application.ApplicationState == UIApplicationState.Active)
{
System.Diagnostics.Debug.WriteLine(userInfo);
var aps_d = userInfo["aps"] as NSDictionary;
var alert_d = aps_d["alert"] as NSDictionary;
var body = alert_d["body"] as NSString;
var title = alert_d["title"] as NSString;
debugAlert(title, body);
}
}
// iOS 10, fire when recieve notification foreground
[Export("userNotificationCenter:willPresentNotification:withCompletionHandler:")]
public void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action<UNNotificationPresentationOptions> completionHandler)
{
System.Console.WriteLine(notification.Request.Content.UserInfo);
var title = notification.Request.Content.Title;
var body = notification.Request.Content.Body;
debugAlert(title, body);
}
private void connectFCM()
{
Console.WriteLine("connectFCM\tEjecutandose la función.");
Messaging.SharedInstance.Connect((error) =>
{
if (error == null)
{
//TODO: Change Topic to what is required
Messaging.SharedInstance.Subscribe("/topics/all");
}
//System.Diagnostics.Debug.WriteLine("connectFCM\t" + (error != null ? "error occured" : "connect success"));
Console.WriteLine("connectFCM\t" + (error != null ? "error occured" + error.DebugDescription : "connect success"));
});
}
private void debugAlert(string title, string message)
{
var alert = new UIAlertView(title ?? "Title", message ?? "Message", null, "Cancel", "OK");
alert.Show();
}
public void ApplicationReceivedRemoteMessage(RemoteMessage remoteMessage)
{
Console.WriteLine("\n*******************************************");
Console.WriteLine("AplicationReceivedRemoteMessage\t" + remoteMessage.AppData);
Console.WriteLine("\n*******************************************");
var title = remoteMessage.AppData.ValueForKey(new NSString("title"));
var text = remoteMessage.AppData.ValueForKey(new NSString("text"));
debugAlert("" + title, "" + text);
}
[Export("userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:")]
public void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler)
{
debugAlert("DidreceiveNotificationResponse", response + "" );
}
For more info, my info.plist contais the key:
<key>UIBackgroundModes</key>
<array>
<string>location</string>
<string>bluetooth-central</string>
<string>bluetooth-peripheral</string>
<string>fetch</string>
<string>remote-notification</string>
</array>
After a long investigation I solve it.
It is necesary to add that key to Entile.plist file.
<dict>
<key>aps-environment</key>
<string>development</string>
</dict>

Xamarin.Forms - Push Notification - iOS

I try to add to my project GCM for iOS
(https://components.xamarin.com/view/googleiosgcm)
This is my code:
[Register ("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate, IInstanceIdDelegate, IReceiverDelegate
{
public Google.Core.Configuration Configuration { get; set; }
NSData DeviceToken { get; set; }
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
NSError err;
Google.Core.Context.SharedInstance.Configure (out err);
if (err != null)
Console.WriteLine ("Failed to configure Google: {0}", err.LocalizedDescription);
Configuration = Google.Core.Context.SharedInstance.Configuration;
// Configure and Start GCM
var gcmConfig = Google.GoogleCloudMessaging.Config.DefaultConfig;
gcmConfig.ReceiverDelegate = this;
Service.SharedInstance.Start (gcmConfig);
// Register for remote notifications
var notTypes = UIUserNotificationType.Sound | UIUserNotificationType.Alert | UIUserNotificationType.Badge;
var settings = UIUserNotificationSettings.GetSettingsForTypes (notTypes, null);
UIApplication.SharedApplication.RegisterUserNotificationSettings (settings);
UIApplication.SharedApplication.RegisterForRemoteNotifications ();
global::Xamarin.Forms.Forms.Init ();
LoadApplication (new App ());
return base.FinishedLaunching (app, options);
}
public override void RegisteredForRemoteNotifications (UIApplication application, NSData deviceToken)
{
// Save our token in memory for future calls to GCM
DeviceToken = deviceToken;
// Configure and start Instance ID
var config = Google.InstanceID.Config.DefaultConfig;
InstanceId.SharedInstance.Start (config);
// Get a GCM token
GetToken ();
}
void GetToken ()
{
// Register APNS Token to GCM
var options = new NSDictionary ();
options.SetValueForKey (DeviceToken, Constants.RegisterAPNSOption);
options.SetValueForKey (new NSNumber(true), Constants.APNSServerTypeSandboxOption);
// Get our token
InstanceId.SharedInstance.Token (
"1055xxxx" ,//My sender id here,
Constants.ScopeGCM,
options,
(token, error) => Console.WriteLine ("GCM Registration ID: " + token));
}
public override void DidReceiveRemoteNotification (UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
{
// Your own notification handling logic here
// Notify GCM we received the message
Service.SharedInstance.AppDidReceiveMessage (userInfo);
}
public override void OnActivated (UIApplication application)
{
Service.SharedInstance.Connect (error => {
if (error != null)
Console.WriteLine ("Could not connect to GCM: {0}", error.LocalizedDescription);
else
Console.WriteLine ("Connected to GCM");
});
}
public override void DidEnterBackground (UIApplication application)
{
Service.SharedInstance.Disconnect ();
}
public void DeleteToken ()
{
InstanceId.SharedInstance.DeleteToken (
"1055xxxx" ,//My sender id here
Constants.ScopeGCM,
error => {
// Callback, non-null error if there was a problem
if (error != null)
Console.WriteLine ("Deleted Token");
else
Console.WriteLine ("Error deleting token");
});
}
int messageId = 1;
// We can send upstream messages back to GCM
public void SendUpstreamMessage ()
{
var msg = new NSDictionary ();
msg.SetValueForKey (new NSString ("1234"), new NSString ("userId"));
msg.SetValueForKey (new NSString ("hello world"), new NSString ("msg"));
var to = "1055xxxxxx" + "#gcm.googleapis.com";
Service.SharedInstance.SendMessage (msg, to, (messageId++).ToString ());
}
[Export ("didDeleteMessagesOnServer")]
public void DidDeleteMessagesOnServer ()
{
// ...
}
[Export ("didSendDataMessageWithID:")]
public void DidSendDataMessage (string messageID)
{
// ...
}
[Export ("willSendDataMessageWithID:error:")]
public void WillSendDataMessage (string messageID, NSError error)
{
// ...
}
and this is console:
You have enabled the CloudMessaging service in Developer Console, but it appears as though your Podfile is missing the line: 'pod "Google/CloudMessaging" or you may need to run pod update in your project directory.
2016-04-26 20:54:43.197 xxxx.iOS[2072:94709] Failed to configure Google: Missing expected subspaces.
GCM | GCM registration is not ready with auth credentials
2016-04-26 20:54:47.712 xxxxxxxx.iOS[2072:94709] Could not connect to GCM: The operation couldn’t be completed. (com.google.gcm error 501.)
I do it from Xamarin.Forms - maybe this is problem???
I did ALL step from getting start but got this problem
Any idea guys what is problem???
For sure - I added file from google to resource folder add did build action - BundleResource
and in info.plist checked remove-notification module
As per the gcm documentation, you should have cocoa pods to integrate their framework.
So make sure you added/update gcm with cocoa pod.
As per the log, pod is not updated.

Why is Xamarin.Auth throwing authentication error with OAuth1Authenticator and Twitter

I am currently using Xamarin.Auth on a iOS project to handle some user authentication via Facebook and Twitter in my application. The Facebook authentication using OAuth2Authenticator works great and my implementation was based mainly off the docs (http://components.xamarin.com/gettingstarted/xamarin.auth). Twitter however still uses OAuth1 it seems and thus I based my implementation mainly off the answer in this StackOverflow questions (https://stackoverflow.com/a/21982205). Everything works properly and I am able to retrieve user, tweets, etc. but after all the code executes I receive a "Authentication Error" popup on the screen saying "Object reference not set to an instance of an object." there is nothing printed to the console however as is the case with most normal errors I have seen thus far. I can dismiss the popup and everything continues to preform correctly. I believe I have narrowed the problem down to something within the OAuth1Authenticator request as I still receive the error when all of the other handling code has been commented out. Please reference the code below to see what might be the cause of this.
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
signupBtn.TouchUpInside += delegate {
LoginToTwitter(true, this);
};
}
void LoginToTwitter(bool allowCancel, UIViewController _vc)
{
var auth = new OAuth1Authenticator (
consumerKey: "My Consumer Key",
consumerSecret: "My Consumer Secret",
requestTokenUrl: new Uri("https://api.twitter.com/oauth/request_token"),
authorizeUrl: new Uri("https://api.twitter.com/oauth/authorize"),
accessTokenUrl: new Uri("https://api.twitter.com/oauth/access_token"),
callbackUrl: new Uri("My callback url"),
getUsernameAsync: (IDictionary<string, string> accountProperties) => {
string screen_name = "";
if (accountProperties.TryGetValue("screen_name", out screen_name)) {
Console.WriteLine("SN: {0}", screen_name);
Account a = new Account(screen_name, accountProperties);
AuthenticatorCompletedEventArgs e = new AuthenticatorCompletedEventArgs(a);
TwitterCompleted(e, _vc);
}
return null;}
);
auth.AllowCancel = allowCancel;
UIViewController authView = auth.GetUI ();
_vc.PresentViewController (authView, true, null);
}
void TwitterCompleted (AuthenticatorCompletedEventArgs e, UIViewController _vc)
{
var theAccount = e.Account;
var theProperties = theAccount.Properties;
foreach (var item in theProperties) {
Console.WriteLine (item); //debugging
}
InvokeOnMainThread (delegate {
_vc.DismissViewController (true, null);
});
AccountStore.Create ().Save (e.Account, "Twitter");
if (!e.IsAuthenticated) {
Console.WriteLine("Not authorized");
return;
}
theScreenName = e.Account.Properties["screen_name"];
theCount = "2";
IDictionary<string, string> theDict = new Dictionary<string, string>();;
theDict.Add("screen_name", theScreenName);
theDict.Add("count", theCount);
var request = new OAuth1Request("GET", new Uri("https://api.twitter.com/1.1/statuses/user_timeline.json"), theDict, e.Account, false);
request.GetResponseAsync().ContinueWith (t => {
if (t.IsFaulted)
Console.WriteLine("Error: {0}", t.Exception.InnerException.Message);
else if (t.IsCanceled)
Console.WriteLine("Canceled");
else
{
var obj = JsonValue.Parse (t.Result.GetResponseText());
Console.WriteLine("object: {0}", obj); // debugging
}
}, uiScheduler);
return;
}
private readonly TaskScheduler uiScheduler = TaskScheduler.FromCurrentSynchronizationContext();
instead of returning null in "getUsernameAsync" return Task

Resources