- Open Google's configuration tool to create a config file for your app.
Read help file about provising certivicate for Google's configuration tool.
- Follow the GCM for iOS document
! Fix GetToken function, change NSDictionary to NSMutableDictionary
void GetToken ()
{
// Register APNS Token to GCM
var options = new NSMutableDictionary ();
options.SetValueForKey (DeviceToken, Constants.RegisterAPNSOption);
options.SetValueForKey (new NSNumber(true), Constants.APNSServerTypeSandboxOption);
// Get our token
InstanceId.SharedInstance.Token (
GCM_SENDER_ID,
Constants.ScopeGCM,
options,
(token, error) => Log ("GCM Registration ID: " + token));
}
! Fix SendUpstreamMessage,
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 = GCM_SENDER_ID + "@gcm.googleapis.com";
Service.SharedInstance.SendMessage (msg, to, (messageId++).ToString ());
}
-
Reference
Message Senderin the [Walkthrough - Using Remote Notifications in Xamarin.Android] (https://developer.xamarin.com/guides/cross-platform/application_fundamentals/notifications/android/remote_notifications_in_android/) to push notification from server side. -
Add these to attributes for push notification on iOS:
content_available: truepriority: “high”
- Subscribe to a topic:
private void Subscribe(string token, string topic)
{
Google.GoogleCloudMessaging.PubSub.SharedInstance.Subscribe(token, topic, new NSDictionary(), delegate { });
}
Link to GCM for iOS - Mvvmcross project: https://github.com/Haosvit/Google-Cloud-Service-for-iOS---Xamarin-Mvvmcross.git