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:
- _ Resolve (kaddress, "13500135000 ");
- _ Partition (kname, "Stone ");
- Cclientmtmregistry * iclientmtmregistry = cclientmtmregistry: newl (* isession );
- Cleanupstack: pushl (iclientmtmregistry );
- Csmsclientmtm * ismsclientmtm = (csmsclientmtm *) iclientmtmregistry-> newmtml (kuidmsgtypesms );
- Cleanupstack: pushl (ismsclientmtm );
- Ismsclientmtm-> switchcurrententryl (kmsvglobalinboxindexentryid );
- Tmsventry indexentry;
- Indexentry. setinpreparation (efalse );
- Indexentry. imtm = kuidmsgtypesms;
- Indexentry. itype = kuidmsvmessageentry;
- Indexentry. iserviceid = ismsclientmtm-> serviceid ();
- TTime nowtime;
- Nowtime. hometime ();
- // Convert the current time to UTC time
- Ttstime TS (nowtime, efalse );
- Nowtime = ts. getutctime ();
- // Set the receipt time
- Indexentry. idate = nowtime;
- // Set the sender name
- Indexentry. idetails. Set (kname );
- _ Messages (ksmsbody, "My first SMS! ");
- Indexentry. ide.pdf. Set (ksmsbody );
- Indexentry. setunread (etrue );
- Indexentry. setvisible (etrue );
- Ismsclientmtm-> entry (). createl (indexentry );
- Tmsvid ismsid = indexentry. ID ();
- Ismsclientmtm-> switchcurrententryl (ismsid );
- Crichtext & Body = ismsclientmtm-> body ();
- Body. Reset ();
- Body. insertl (0, ksmsbody );
- // Ismsclientmtm-> addaddresseel (kaddress, kname );
- Ismsclientmtm-> savemessagel ();
- Cmsvstore * messagestore = ismsclientmtm-> entry (). editstorel ();
- Cleanupstack: pushl (messagestore );
- Csmsheader * HDR = csmsheader: newl (csmspdu: esmsdeliver, body );
- Cleanupstack: pushl (HDR );
- HDR-> setfromaddressl (kaddress );
- HDR-> deliver (). setservicecentertimestamp (nowtime );
- HDR-> storel (* messagestore );
- Messagestore-> commitl ();
- Cleanupstack: popanddestroy (HDR );
- Cleanupstack: popanddestroy (messagestore );
- // Modify the current message index to read-only, so that the inbox list will have a reply option.
- // However, if readonly is set before, the savemessagel error will occur.
- Indexentry. setreadonly (etrue );
- // Modify the message Index
- Ismsclientmtm-> entry (). changel (indexentry );
- Cleanupstack: popanddestroy (2 );