Create a new unread text message in the inbox

Source: Internet
Author: User

I recently learned about MTM and found it interesting to create a new unread text message in the inbox. I can specify the sender's number, name, and time. I tried to solve the following problems, record:

1. The creation is successful, but the recipient rather than the sender is displayed when you view the information details in the inbox. In this way, the information is false. Later, you can check the information and consult others, you also need to process the csmsheader and use setfromaddressl in the csmsheader to add the sender's number.

2. Sending time problems.

When I started the test, I always found that it was normal in the simulator, and the sending time on the real machine was eight hours later than the set time. I thought it should be a time zone problem, later, we tracked the program and found that the tTime hometime () function obtained the UTC time on the simulator, instead of the time displayed in the simulator. What we get on the real machine is the current local time, in MTM, the time in the data packet is UTC time. It is normal to convert the current time and put it in the data packet.

The main code is as follows:

  1. _ Resolve (kaddress, "13500135000 ");
  2. _ Partition (kname, "Stone ");
  3. Cclientmtmregistry * iclientmtmregistry = cclientmtmregistry: newl (* isession );
  4. Cleanupstack: pushl (iclientmtmregistry );
  5. Csmsclientmtm * ismsclientmtm = (csmsclientmtm *) iclientmtmregistry-> newmtml (kuidmsgtypesms );
  6. Cleanupstack: pushl (ismsclientmtm );
  7. Ismsclientmtm-> switchcurrententryl (kmsvglobalinboxindexentryid );
  8. Tmsventry indexentry;
  9. Indexentry. setinpreparation (efalse );
  10. Indexentry. imtm = kuidmsgtypesms;
  11. Indexentry. itype = kuidmsvmessageentry;
  12. Indexentry. iserviceid = ismsclientmtm-> serviceid ();
  13. TTime nowtime;
  14. Nowtime. hometime ();
  15. // Convert the current time to UTC time
  16. Ttstime TS (nowtime, efalse );
  17. Nowtime = ts. getutctime ();
  18. // Set the receipt time
  19. Indexentry. idate = nowtime;
  20. // Set the sender name
  21. Indexentry. idetails. Set (kname );
  22. _ Messages (ksmsbody, "My first SMS! ");
  23. Indexentry. ide.pdf. Set (ksmsbody );
  24. Indexentry. setunread (etrue );
  25. Indexentry. setvisible (etrue );
  26. Ismsclientmtm-> entry (). createl (indexentry );
  27. Tmsvid ismsid = indexentry. ID ();
  28. Ismsclientmtm-> switchcurrententryl (ismsid );
  29. Crichtext & Body = ismsclientmtm-> body ();
  30. Body. Reset ();
  31. Body. insertl (0, ksmsbody );
  32. // Ismsclientmtm-> addaddresseel (kaddress, kname );
  33. Ismsclientmtm-> savemessagel ();
  34. Cmsvstore * messagestore = ismsclientmtm-> entry (). editstorel ();
  35. Cleanupstack: pushl (messagestore );
  36. Csmsheader * HDR = csmsheader: newl (csmspdu: esmsdeliver, body );
  37. Cleanupstack: pushl (HDR );
  38. HDR-> setfromaddressl (kaddress );
  39. HDR-> deliver (). setservicecentertimestamp (nowtime );
  40. HDR-> storel (* messagestore );
  41. Messagestore-> commitl ();
  42. Cleanupstack: popanddestroy (HDR );
  43. Cleanupstack: popanddestroy (messagestore );
  44. // Modify the current message index to read-only, so that the inbox list will have a reply option.
  45. // However, if readonly is set before, the savemessagel error will occur.
  46. Indexentry. setreadonly (etrue );
  47. // Modify the message Index
  48. Ismsclientmtm-> entry (). changel (indexentry );
  49. Cleanupstack: popanddestroy (2 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.