Example #1
0
        public static bool Init(string appKey, string appSecret, UIApplication application, NSDictionary options, bool debug = false)
        {
            try
            {
                ALBBMANAnalytics.Instance.InitWithAppKey(appKey, appSecret);
                if (debug)
                {
                    ALBBMANAnalytics.Instance.TurnOnDebug();
                }

                #region 阿里推送
                RegisterAPNS(application);
                InitCloudPush(appKey, appSecret);

                NSNotificationCenter.DefaultCenter.AddObserver((NSString)"CCPDidChannelConnectedSuccess", (NSNotification notification) =>
                {
                    Console.WriteLine("消息通道建立成功");
                });

                options = options ?? new NSDictionary();
                CloudPushSDK.SendNotificationAck(options);

                //同步角标数到服务端
                nint num = UIApplication.SharedApplication.ApplicationIconBadgeNumber;
                //每次打开APP 角标就置空0
                CloudPushSDK.SyncBadgeNum(0, (CloudPushCallbackResult res) =>
                {
                    if (res.Success)
                    {
                        Console.WriteLine("同步角标成功");
                    }
                    else
                    {
                        Console.WriteLine("同步角标失败");
                    }
                });
                #endregion

                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine("初始化阿里错误:" + ex.Message);
                return(true);
            }
        }
Example #2
0
 /// <summary>
 /// SDK初始化
 /// </summary>
 static void InitCloudPush(string appkey, string appSecret)
 {
     CloudPushSDK.AsyncInit(appkey, appSecret, (CloudPushCallbackResult res) =>
     {
         if (res.Success)
         {
             Console.WriteLine("Push SDK init success, deviceId:" + CloudPushSDK.DeviceId);
             Xamarin.Forms.Device.BeginInvokeOnMainThread(() =>
             {
                 UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
             });
         }
         else
         {
             Console.WriteLine("Push SDK init failed, error:" + res.Error);
         }
     });
 }
Example #3
0
 public static (string, UIApplicationState) DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo)
 {
     // 通知打开回执上报
     CloudPushSDK.SendNotificationAck(userInfo);
     //active正在打开状态,还没做
     // 应用在前台 或者后台开启状态下,直接跳转页面。
     if (application.ApplicationState == UIApplicationState.Active || application.ApplicationState == UIApplicationState.Inactive || application.ApplicationState == UIApplicationState.Background)
     {
         //取得APNS通知内容
         NSDictionary aps = (NSDictionary)userInfo.ValueForKey((NSString)"aps");
         // 内容
         string content = aps.ValueForKey((NSString)"alert").ToString();
         // 播放声音
         string sound = aps.ValueForKey((NSString)"sound").ToString();
         // badge数量
         //int bajge = aps.ValueForKey((NSString)"badge");
         // 取得Extras字段内容,
         //服务端中Extras字段,key是自己定义的
         string Extras = aps.ValueForKey((NSString)"Extras").ToString();
     }
     return((NSString)userInfo.ValueForKey((NSString)"Url"), application.ApplicationState);
 }