2.相片下载 using DataSync; //进度条回调函数 //参数:transfered已传输字节数, total 表示总字节数 //返回值: true:中断传输,false:继续传输 public static bool TransferProgress(int transfered,int total) {
return false; } static void Main() { DataSyncObject ds = new DataSyncObject();//创建DataSyncObject对像 ds.gIcloud = new Cloud();//生成gIcloud对像 Context loginctx = new Context();//生成Context对像 loginctx.loginUsername = "apple id ";//输入icoud 帐号 loginctx.loginPassword = "password";//输入icoud 帐号密码 loginctx.modeType = Context.ICLOUD_MODE;//输入Context参数的模块类型,当前设为登陆到icloud服务器上 bool ret = ds.login(loginctx);//登陆icoud,成功返回true,失败返回false; if (ret == false) { return; }
//登陆后,便可以下载相片 Context getctx ; List<FileNode> files = ds.gIcloud.getPhotoList();//登陆成功后,通过该方法取得需要下载的文件列表 foreach (FileNode item in files) { getctx = new Context(); getctx.transferProgresscallback = new TransferProgressCallBack(TransferProgress);//进度条回调接口 getctx.modeType = Context.ICLOUD_PS_MODE;//指定要操作的模块为相片流模块 getctx.inItem = item;//要下载的文件节点 ds.get(getctx);//下载文件 if (getctx.outItem != null) { Console.Write("\n\n file " + getctx.outItem.filename + "down success."); } } } |
3.上传相片 using DataSync; //进度条回调函数 //参数:transfered已传输字节数, total 表示总字节数 //返回值: true:中断传输,false:继续传输 public static bool TransferProgress(int transfered,int total) {
return false; } static void Main() { DataSyncObject ds = new DataSyncObject();//创建DataSyncObject对像 ds.gIcloud = new Cloud();//生成gIcloud对像 Context loginctx = new Context();//生成Context对像 loginctx.loginUsername = "apple id ";//输入icoud 帐号 loginctx.loginPassword = "password";//输入icoud 帐号密码 loginctx.modeType = Context.ICLOUD_MODE;//输入Context参数的模块类型,当前设为登陆到icloud服务器上 bool ret = ds.login(loginctx);//登陆icoud,成功返回true,失败返回false; if (ret == false) { return; }
//登陆后,便可以上传相片 Context putctx = new Context(); putctx.transferProgresscallback = new TransferProgressCallBack(TransferProgress); putctx.srcFileFullName = "e:/ndphoto/IMG_0255.JPG";//指定要上传的文件 putctx.modeType = Context.ICLOUD_PS_MODE; ret = ds.put(putctx); //上传一张相片,最大不能超过50M if (ret) { Console.Write("\n\n file put success. "); } } |
7.增加联系人 using DataSync; static void Main() { DataSyncObject ds = new DataSyncObject();//创建DataSyncObject对像 ds.gIcloud = new Cloud();//生成gIcloud对像 Context loginctx = new Context();//生成Context对像 loginctx.loginUsername = "apple id ";//输入icoud 帐号 loginctx.loginPassword = "password";//输入icoud 帐号密码 loginctx.modeType = Context.ICLOUD_MODE;//输入Context参数的模块类型,当前设为登陆到icloud服务器上 bool ret = ds.login(loginctx);//登陆icoud,成功返回true,失败返回false; if (ret == false) { return; } //增加联系人 List<Contact> contacts = new List<Contact>(); Contact contact = new Contact { prefix = "pre", firstName = "aaa", lastName = "bbb", middleName = "ccc",phoneticLastName = "", phoneticFirstName = "Nicolas",suffix = "suff",nickName = "nickname", jobTitle = "jobTitle", department = "systemSport", companyName = "nd", birthday = "1999-01-01",notes = "测试添加一个完整的联系人" }; 电话 contact.phones = new List<Phone>(); Phone phone1 = new Phone { label = "WORK", field = "13635260966" }; Phone phone2 = new Phone { label = "HOME", field = "059122321966" }; Phone phone3 = new Phone { label = "custum", field = "15918726583" }; contact.phones.Add(phone1); contact.phones.Add(phone2); contact.phones.Add(phone3);
邮件 contact.emailAddresses = new List<EmailAdr>(); EmailAdr emailAdr1 = new EmailAdr { label = "WORK", field = "test_1@yahoo.com.cn" }; EmailAdr emailAdr2 = new EmailAdr { label = "HOME", field = "test_2@gmail.com" }; EmailAdr emailAdr3 = new EmailAdr { label = "custum", field = "test_3@me.com" }; contact.emailAddresses.Add(emailAdr1); contact.emailAddresses.Add(emailAdr2); contact.emailAddresses.Add(emailAdr3);
地址 contact.streetAddresses = new List<StreetAdr>();
StreetField streetField1 = new StreetField(); streetField1.city = "city"; streetField1.country = "country"; streetField1.state = "state"; streetField1.street = "street"; streetField1.countryCode = "countryCode"; StreetAdr streetAdr1 = new StreetAdr { label = "HOME", field = streetField1 };
StreetField streetField2 = new StreetField(); streetField1.city = "city"; streetField1.country = "country"; streetField1.state = "state"; streetField1.street = "street"; streetField1.countryCode = "countryCode"; StreetAdr streetAdr2 = new StreetAdr { label = "WORK", field = streetField2 };
StreetField streetField3 = new StreetField(); streetField1.city = "city"; streetField1.country = "country"; streetField1.state = "state"; streetField1.street = "street"; streetField1.countryCode = "countryCode"; StreetAdr streetAdr3 = new StreetAdr { label = "custum", field = streetField3 }; contact.streetAddresses.Add(streetAdr1); contact.streetAddresses.Add(streetAdr2); contact.streetAddresses.Add(streetAdr3);
主页 contact.urls = new List<Url>(); Url url1 = new Url { label = "WORK", field = "www.sina.com" }; Url url2 = new Url { label = "HOME", field = "www.apple.com" }; Url url3 = new Url { label = "custum", field = "www.google.com" }; contact.urls.Add(url1); contact.urls.Add(url2); contact.urls.Add(url3);
概况 contact.profiles = new List<Profile>(); Profile profile1 = new Profile { label = "Facebook", field = "http://twitter.com",user = "sdfdf" }; Profile profile2 = new Profile { label = "custum", field = "http://facebook.com",user = "jjjjjj" }; contact.profiles.Add(profile1); contact.profiles.Add(profile2);
日期 contact.dates = new List<Date>(); Date date1 = new Date { label = "other", field = "2011-01-01" }; Date date2 = new Date { label = "custum", field = "2012-01-01" }; contact.dates.Add(date1); contact.dates.Add(date2);
相关人 contact.relatedNames = new List<RelatedName>(); RelatedName relatedName1 = new RelatedName { label = "other", field = "father" }; RelatedName relatedName2 = new RelatedName { label = "custum", field = "brother" }; contact.relatedNames.Add(relatedName1); contact.relatedNames.Add(relatedName2);
通讯 contact.IMs = new List<IM>();
IMsfield iMsfield1 = new IMsfield(); iMsfield1.IMService = "QQ"; iMsfield1.userName = "qqusername"; IMsfield iMsfield2 = new IMsfield(); iMsfield2.IMService = "Facebook"; iMsfield2.userName = "testname";
IM iMs1 = new IM { label = "QQ", field = iMsfield1 }; IM iMs2 = new IM { label = "weibo", field = iMsfield2 }; contact.IMs.Add(iMs1); contact.IMs.Add(iMs2);
contacts.Add(contact); Context ctx = new Context(); ctx.modeType = Context.ICLOUD_CONTACT_MODE; ctx.contactList = contacts; ds.put(ctx); } |
8.修改联系人 using DataSync; static void Main() { DataSyncObject ds = new DataSyncObject();//创建DataSyncObject对像 ds.gIcloud = new Cloud();//生成gIcloud对像 Context loginctx = new Context();//生成Context对像 loginctx.loginUsername = "apple id ";//输入icoud 帐号 loginctx.loginPassword = "password";//输入icoud 帐号密码 loginctx.modeType = Context.ICLOUD_MODE;//输入Context参数的模块类型,当前设为登陆到icloud服务器上 bool ret = ds.login(loginctx);//登陆icoud,成功返回true,失败返回false; if (ret == false) { return; } //修改联系人 Context ctx = new Context(); ctx.modeType = Context.ICLOUD_CONTACT_MODE; ds.get(ctx); List<Contact> contactList = ctx.outContactList; List<Contact> contacts = new List<Contact>(); Contact contact = contactList[0]; contact.firstName = "aaa"; contact.lastName = "bbb"; contact.phones = new List<Phone>(); Phone phone = new Phone { label = "WORK", field = "987654321" }; contact.phones.Add(phone); contacts.Add(contact); Context ctx = new Context(); ctx.modeType = Context.ICLOUD_CONTACT_MODE; ctx.contactList = contacts; ds.updata(ctx); } |
9.删除指定联系人 using DataSync; static void Main() { DataSyncObject ds = new DataSyncObject();//创建DataSyncObject对像 ds.gIcloud = new Cloud();//生成gIcloud对像 Context loginctx = new Context();//生成Context对像 loginctx.loginUsername = "apple id ";//输入icoud 帐号 loginctx.loginPassword = "password";//输入icoud 帐号密码 loginctx.modeType = Context.ICLOUD_MODE;//输入Context参数的模块类型,当前设为登陆到icloud服务器上 bool ret = ds.login(loginctx);//登陆icoud,成功返回true,失败返回false; if (ret == false) { return; } //删除联系人 Context ctx = new Context(); ctx.modeType = Context.ICLOUD_CONTACT_MODE; ds.get(ctx); List<Contact> contactList = ctx.outContactList; List<Contact> delContacts = new List<Contact>(); Phone phone = new Phone { label = "WORK", field = "15935260966" }; Contact contact = contactList[0]; delContacts.Add(contact); Context ctx = new Context(); ctx.modeType = Context.ICLOUD_CONTACT_MODE; ctx.contactList = delContacts; ds.delete(ctx); } |