微软c xaml开发应用程序教程_第1页
微软c xaml开发应用程序教程_第2页
微软c xaml开发应用程序教程_第3页
微软c xaml开发应用程序教程_第4页
微软c xaml开发应用程序教程_第5页
已阅读5页,还剩46页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1WindowsPhone821WindowsPhone82WindowsPhone应3WindowsPhone应4WindowsPhone85WindowsPhone8678推送通9WindowsPhone集1011WindowsPhone81211WindowsPhone81213WindowsPhone814WindowsPhone815钱1617WindowsPhone商18WindowsPhone8企业应用19Windows8WindowsPhone820蓝牙概应用中使近场通应用中使WindowsPhone8WindowsPhone8WindowsPhone8蓝蓝牙是一种无线通信技术,通过它米范围以内的设备可以互相通信蓝牙是一蓝牙是一种短距离无线通信技米范围以内的设备可以互相通应用到设在应用到设备的通信中,应用使用蓝牙发现其他提供该应用想要访问的服务的应用到应在应用到应用的通信中,应用使用蓝牙发现另一播发该应用想要访问的服务的应 连应用对应用对设备的方案中,设备必须先与在配对前,设备的蓝牙功能需设置为“可被发现在配对的连接中进行身份验用户可能需要输入验证Phone手机配对于应用到应用的蓝牙连接,应用会搜索其他手机上运行的不需要配对即可相互在所谓的发在所谓的发现/查询期间,设备可以枚举该范围内处于检测状态的其他设备可以查询特定服务支持的服务列表,并最终与设上的这些服务建立蓝牙服务在手机上必须设置为有TheID_CAP_PROXIMITYandcapabilitiesmustbeenabledfortheapplicationtomakeuseoftheBluetoothcommunicationstoadeviceThePeerFinderThePeerFinderclasscanbeusedtosearchforpairedThesearchwillfailwiththeexceptionshownaboveifBluetoothisswitchedPeerFinder.AlternateIdentities["Bluetooth:Paired"]=varpeers=await}catch(Exception{if((uint)ex.HResult==0x8007048F)MessageBox.Show("Bluetoothisswitchedoff");}应用程序启动一个“设置应用程序启动一个“设置”属性:获取或设置将显示的网络连接设置的类许多内置于WindowsPhone的应用,都可以通过调用和传入一个URI,从您的应用启动。例如,以下调用可以启动蓝牙设用与要启动应用相关的方案用Windows.System.Launcher.LaunchUriAsync(newUri("ms-settings-ConnectionSettingsTaskconnectionSettingsTask=newConnectionSettingsTask();connectionSettingsTask.ConnectionSettingsType=ConnectionSettingsType.Bluetooth;您可以使用PeerFinder.FindAllPeersAsync 。如果没有对等设备则列表为空,列表计数为StringBuilderlist=newforeach(PeerInformationpin{}方法开启对远程主方法开启对远程主机连接的异步请在以下的代码中的连接操上启动远程主机名和远程服务名所指定的远程网络目必须提,或remoteServiceName参数。如remoteHostNamenull或空字符串,则会出现错//JustusethefirstPeerPeerInformationpartner=peers[0];//AttemptaStreamSocketsocket=newawaitsocket.ConnectAsync(partner.HostName,当蓝牙关当蓝牙关闭时,调用来检测到手机上蓝牙的关闭状将引发异常。通常可通过使用下列代码捕捉此异//SearchforallpaireddevicesPeerFinder.AlternateIdentities["Bluetooth:Paired"]="";{varpeers=await//HandletheresultoftheFindAllPeersAsync}catch(Exception{if((uint)ex.HResult=={MessageBox.Show("Bluetoothisturned}}应用到应应用到应用通信允许两个程序通过蓝牙交互数在应用到应用的通信中,应用使用蓝牙发现另一播发该应用想要访问的服务的应用之间建StreamSocket执行应用到应用通信的设备间不需要执行配能力必须启发现是寻找播发您发现是寻找播发您想要交互的服务的蓝牙设备或应用的应用可通过设请注意长时间这样做会损耗电//RegisterforincomingconnectionrequestsPeerFinder.ConnectionRequested+=PeerFinder_ConnectionRequested;//StartadvertisingourselvessothatourpeerscanfindPeerFinder.DisplayName="PSR";应用程序可以订应用程序可以订阅事当触发事件时应用程序然后可以决定是否接受该请它可以向用户显示一个确认对话//Registerforincomingconnectionrequests//StartadvertisingourselvessothatourpeerscanfindusPeerFinder.DisplayName="PSR";上面的代上面的代码创建“RobsPhone”使用ConnectionRequestedEventArgsPeerInformation属性确定发送请求的是StreamSocketasyncvoidPeerFinder_ConnectionRequested(objectsender,ConnectionRequestedEventArgs{if(args.PeerInformation.DisplayName=="RobsPhone"{socket=awaitPeerFinder.ConnectAsync(args.PeerInformation);}}连接到由对方法的调用发现的对StreamSocketasyncvoidPeerFinder_ConnectionRequested(objectsender,ConnectionRequestedEventArgs{if(args.PeerInformation.DisplayName=="RobsPhone"{}}socket=await此语句停此语句停止播发目的为停止其他的接入请求,以及降低功StreamSocketasyncvoidPeerFinder_ConnectionRequested(objectsender,ConnectionRequestedEventArgs{if(args.PeerInformation.DisplayName=="RobsPhone"{socket=await}}此方法此方法为从流套接字读取字符串文字符串长度作为异步读取消息的输入参privateDataReaderprivateasyncTask<string>{if(dataReader==null) dataReader=newDataReader(socket.InputStream);awaitdataReader.LoadAsync(4);uintmessageLen=(uint)dataReader.ReadInt32();awaitdataReader.LoadAsync(messageLen);return}DataReader对象DataReader对象上的远程目标读取的输入privateDataReaderprivateasyncTask<string>{if(dataReader==null) dataReader=newDataReader(socket.InputStream);awaitdataReader.LoadAsync(4);uintmessageLen=(uint)dataReader.ReadInt32();awaitdataReader.LoadAsync(messageLen);return}此语句从输入此语句从输入流加4个字传入的个字节被转换为整数值,表示正在传送的字节privateDataReaderprivateasyncTask<string>{if(dataReader== dataReader=newawaitdataReader.LoadAsync(messageLen);}awaituintmessageLen=此语句将此语句将加载的字符串的文输入参数为字符串长读取完成后,会被转换成一个字符串并返privateDataReaderprivateasyncTask<string>{if(dataReader==null) dataReader=newDataReader(socket.InputStream);awaitdataReader.LoadAsync(4);uintmessageLen=}awaitdataReader.LoadAsync(messageLen);returndataReader.ReadString(messageLen);GetMessageGetMessageawait关键字的任当任务完成时,messagestringmessage=await方法将发方法将发送字符串至输出DataWriter格式化输出DataWriterprivateasyncvoidSendMessage(string{if(dataWriter==dataWriter=newawaitdataWriter.StoreAsync();awaitdataWriter.StoreAsync();}创建并初创建并初始化指向某输出流的数据编写器的dataWriterDataWriterprivateasyncvoidSendMessage(string{awaitdataWriter.StoreAsync();awaitdataWriter.StoreAsync();}if(dataWriter==dataWriter=new3232位整数值写入输出将缓冲区中的数据提交到备份存储DataWriterprivateasyncvoidSendMessage(string{if(dataWriter==dataWriter=newawaitdataWriter.StoreAsync();}awaitdataWriter.StoreAsync();将字符串将字符串值写入输出将缓冲区中的数据提交到备份存储DataWriterprivateasyncvoidSendMessage(string{if(dataWriter==dataWriter=newawaitdataWriter.StoreAsync();}awaitdataWriter.StoreAsync();不能使不能使用模拟器测试蓝牙应用程应用程序可以检查出设备是否是模拟if(Microsoft.Devices.Environment.DeviceType=={MessageBox.Show("NoBluetoothonthe}当设当设备之间的距离3-4厘米(1-1.5英寸)内时发生424kbits/s30kbits/s60kbits/s之通信是非常具有选择性和意图性的,因为用户有意将各自的设备放在一起进行也可以NFCNFC芯片或标记之间发生最适合在最适合在设备间传递少量的数据连接设获取内交换数字对您可以使用手机交换电子名片或在应用中使用在应用中使用应用程序使用NFC在设备间简单的传输应用程序可以订阅消息事件和接收特定类型的字符串使用ProximityDevice使用ProximityDevice类在应用之间传递简单的类型以“Windows”开始时可以发布消息。要使用另一消息类型发布消息,如“WindowsMime”。或“NDEF:WriteTag”PublishBinaryMessage方法只有在其ProximityDevicedevice=//MakesureNFCissupportedif(device!=null){longid=device.PublishMessage("Windows.JumpStartMessageType","HelloFrom}消息的发消息的发IDPublishMessage、PublishUriMessage方法返消息将持续发布,直到调用了StopPublishingMessage方法或者释放了ProximityDeviceprivatevoidStopPublishingMessage(objectsender,RoutedEventArgs{publishedMessageId=-1;}方法的输方法的输入参数为消息类型和接收代以上的代码中消息类型是您可自定义消息ProximityDevicedevice=//MakesureNFCissupportedif(device!=null){longid=device.SubscribeForMessage("Windows.JumpStartMessageType",}当消息接当消息接收事件被触发后,回调函数将处理接收的数消息类型相同时事件才会被触在此例中接收到类型为的消息后回调函数被执privatevoidmessageReceived(ProximityDevicesender,ProximityMessage{MessageBox.Show("Messagereceived"+message.DataAsString+"from"+}消息订阅消息订阅的订ID取消消息订方法返Windows8Windows8在这种用法类用于搜索应用在其他设备上的实ProximityDevicedevice=//MakesureNFCissupportedif(device!=null){PeerFinder.TriggeredConnectionStateChanged+=//Startfindingpeerapps,whilemakingthisappdiscoverablebypeers}Windows8Windows8appId属性获取要与其他平台上的对等应用程序匹配的备ProximityDevicedevice=//MakesureNFCissupportedif(device!=null){PeerFinder.TriggeredConnectionStateChanged+=//IncludetheWindows8versionofourappaspossiblepeerPeerFinder.AlternateIdentities.Add("Windows","myWin8appID");//Startfindingpeerapps,whilemakingthisappdiscoverablebypeers}套接字连接失败套接字连接失败后重新连接建立连接时,保RemoteHostNameRemoteServiceName属性 事件中,如果有活动套接字连接,则保新连和值,因为这表示应用希望在继续时stringstoredRemoteHostRawName=socket.Information.RemoteHostName.RawName;stringstoreRemoteServiceName=socket.Information.RemoteServiceName;//Persistthesetwo套接字连接失败后重新连接套接字连接失败后重新连接象方使用在步中保存RemoteHostName值创建新5.创建新的套接字,调用ConnectAsync,并传入storedRemoteServiceName和新创建awaitsocket.ConnectAsync(newRemoteHostName,HostNamenewRemoteHostName=new为建立为建立的基础套接字不受保护。默认不加密数据信道上属性值作为对称密钥这可以在加密库中使用, System.Security.Cryptography.AesManaged只有彼此处于近距离的设备知道此密钥WindowsPhoneWindowsPhone模拟器没有任何用于测试邻近感应的内置运行,要求您使用支持NFCWindowsPhone8NFC功能。有关示例,请参ProximityTapper的的正式支持NFCNFCWindowsWindowsPhone8引入了可以用于开发使用蓝牙通信的应用的API。通过使用这些API用可以连接到另一应用或设备在应用到设备的方案中,您仅能够发现已与运行该应用的手机配对的设备既可以在运WindowsPhone8的手机之间进行临近感应通信,也可以WindowsPhone8手机和不同种类的设备(如运行Windows的计算机)之间进行通信NFC建立的基础套接字不受保护。默认不加密数据信道。若要加密通过该套接字传递的在应用在应用的事件中,如果有活动套接字连接,则保TheinformationhereinisforinformationalpurposesonlyanrepresentsTheinformationhereinisforinformationalpurposesonlyanrepresentsthecurrentviewofMicrosoftCorporationasofthedateofthispresentation.BecauseMicrosoftmustrespondtochangingmarketconditions,itshouldnotbeinterpretedtobeacommitmentonthepartofMicrosoft,andMicrosoftcannotguaranteetheaccuracyofanyinformationprovidedafterthedateofthispresentation.MICROSOFTMAKESNOWARRANTIES,EXPRESS,IMPLIEDORSTATUTORY,ASTOTHEINFORMATIONINTHISPRESENTATION.©2012MicrosoftAllrightsreserved.Microsoft,Windows,WindowsVistaandotherproductnamesareormayberegisteredtrademarksand/ortrademarksintheU.S.and/orotherTheinformationhereinisforinformationalpurposesonlyanrepresentsthecurrentviewofMicrosoftCorporationasofthedateofthispresentation.BecauseMicrosoftmustrespondtochan

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论