开发者

Tile notification with php

开发者 https://www.devze.com 2023-03-11 00:41 出处:网络
I\'m trying to send to my phone a tile notification using this library http://phpwindowsphonepush.codeplex.com/

I'm trying to send to my phone a tile notification using this library http://phpwindowsphonepush.codeplex.com/ but the phone does not receive the notification only when I enter the URL of remote image. This is my simple php code

$uri="http://db3.notify.live.net/throttledthirdparty/01.00/AAEyQ7xxxxxxxxxxx";

$notif=new WindowsPhonePushNotification($uri);

$imm="http://www.mysite.net/imm/1.jpg";

$notif->push_tile($imm, "Title","2");

this is开发者_StackOverflow中文版 c# code

private HttpNotificationChannel channel;

    public MainPage()
    {
        InitializeComponent();

        try
        {
            StartChannel();
        }
        catch (InvalidOperationException ioe)
        {
            HandleChannelException(ioe);
        }
    }



    private void HandleChannelException(InvalidOperationException ioe)
    {
        MessageBox.Show(ioe.Message);
    }

    private void StartChannel()
    {
        channel = HttpNotificationChannel.Find("test1");
        if (channel == null)
        {
            channel = new HttpNotificationChannel("test1", "name");
            AddDelegates();
            channel.Open();
        }
        else
        {
            AddDelegates();
        }

        if (channel.ChannelUri != null)
        {
            OnChannelReady();
        }
    }

    private void AddDelegates()
    {
        channel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(channel_ChannelUriUpdated);
        channel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(channel_ErrorOccurred);
        channel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(channel_HttpNotificationReceived);
    }

    private void channel_HttpNotificationReceived(object sender, HttpNotificationEventArgs e)
    {

        StreamReader sr = new StreamReader(e.Notification.Body, Encoding.UTF8);
        string text = sr.ReadToEnd();
        this.Dispatcher.BeginInvoke(() => MessageBox.Show(text));
    }



    private void channel_ErrorOccurred(object sender, NotificationChannelErrorEventArgs e)
    {

        MessageBox.Show("ERROR");

    }

    private void channel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)
    {
        try
        {
            this.Dispatcher.BeginInvoke(OnChannelReady);
        }
        catch (InvalidOperationException ioe)
        {
            this.Dispatcher.BeginInvoke(() => HandleChannelException(ioe));
        }
    }

    private void OnChannelReady()
    {

        if (!this.channel.IsShellTileBound)
            this.channel.BindToShellTile();

    }

this is a log file:

* About to connect() to db3.notify.live.net port 80
*   Trying xx.xx.xx.xxx... * connected
* Connected to db3.notify.live.net (xxx.xx.xx.xxx) port 80
> POST /throttledthirdparty/01.00/AAE0ykxoIaknSoMXxxxxxxxxxxxx HTTP/1.1
Host: db3.notify.live.net
Accept: */*
X-WindowsPhone-Target: token
X-NotificationClass: 1
Content-Length: 240
Content-Type: application/x-www-form-urlencoded
<?xml version="1.0" encoding="utf-8"?>
<wp:Notification xmlns:wp="WPNotification">
<wp:Tile>
<wp:BackgroundImage>http://www.mysite.net/imm/1.jpg</wp:BackgroundImage>
<wp:Count>2</wp:Count>
<wp:Title>6</wp:Title>
</wp:Tile> 
</wp:Notification>< HTTP/1.1 200 OK
< Cache-Control: private
< Server: Microsoft-IIS/7.5
< X-DeviceConnectionStatus: Connected
< X-NotificationStatus: Received
< X-SubscriptionStatus: Active
< X-MessageID: 00000000-0000-0000-0000-000000000000
< ActivityId: xxxxxx-83fa-423d-8240-ec610eca749b
< X-Server: DB3MPNSM005
< X-AspNet-Version: 4.0.30319
< X-Powered-By: ASP.NET
< Date: Tue, 07 Jun 2011 11:57:18 GMT
< Content-Length: 0
* Connection #0 to host db3.notify.live.net left intact
* Closing connection #0


OK, that will teach me to look carefully at the code - if you call BindToShellTile() without arguments, you can only use local resources for the tile. However, if you create a new Collection and pass that collection in as an argument, you will be able to access local or remote images in the tile.

eg.

Collection<Uri> TileLocations = new Collection<Uri> { new Uri(@"/Background.jpg") };
TileLocations.Add(new Uri("http://jquery.andreaseberhard.de"));
if (!channel.IsShellTileBound) { channel.BindToShellTile(TileLocations); }

Should do the trick. The collection of URIs should contain all the possible domains from which images may be retrieved. In this case, anything at http://jquery.andreasebernhard.de would be valid images. For details see this page

Now calling $notif->push_>tile("http://jquery.andreaseberhard.de/pngFix/pngtest.png","title","2"); should work with a remote image.

0

精彩评论

暂无评论...
验证码 换一张
取 消