ios - skscene UIViewController send SMS from SKScene -
i trying allow player share score sms when game over.
i have imported framework in project. imported in viewcontroller.h file.
here viewcontroller.h file
#import <uikit/uikit.h> #import <spritekit/spritekit.h> #import <messageui/messageui.h> @interface myviewcontroller : uiviewcontroller <mfmessagecomposeviewcontrollerdelegate> { } @end
i tried import myscene.h so:
#import <messageui/messageui.h> @interface myscene : skscene <mfmessagecomposeviewcontrollerdelegate> { }
when want show sms share, use code in myscene.m file
mfmessagecomposeviewcontroller *textcomposer = [[mfmessagecomposeviewcontroller alloc] init]; [textcomposer setmessagecomposedelegate:self]; if ([mfmessagecomposeviewcontroller cansendtext]) { [textcomposer setrecipients:[nsarray arraywithobject:nil]]; [textcomposer setbody:@"happy happy joy joy!"]; [self presentviewcontroller:textcomposer animated:yes completion:null]; } else { nslog(@"cant send text!"); }
but on line
[self presentviewcontroller:textcomposer animated:yes completion:null];
i "no visible @interface 'myscene' declares selector 'presentviewcontroller:animated:completion:'" error.
i have tried search last couple hours. try god knows how many variations , examples other posts/tutorials(which learn few things unrelated this). nothing seems work. starting run out of hair pull out. great. sure of gurus here should walk in park. thanks.
edit: not using storyboard, or view controller buttons/menu/game play etc...hence why not able call function within viewcontroller itself.
edit: tried paulw11 suggested in link. have following errors.
in myviewcontroller
myscene.myviewcontroller = self;
i "property 'myviewcontroller' not found on object of type 'myscene'" error
also in myscene.m
- (void)sendtocontroller { nslog(@"ok"); // use already-created spriteviewcontroller [_myviewcontroller sendsms]; }
[_myviewcontroller sendsms]; line "no visible @interface 'myviewcontroller' declares selector 'sendsms'"
edit 2: *edit 2:* edit 2: *edit 2:*
i got open sms. small problem, not allow me dismiss /cancel.
here sendsms code:
-(void) sendsms { mfmessagecomposeviewcontroller *textcomposer = [[mfmessagecomposeviewcontroller alloc] init]; [textcomposer setmessagecomposedelegate:self]; if ([mfmessagecomposeviewcontroller cansendtext]) { [textcomposer setrecipients:[nsarray arraywithobject:@" "]]; nsstring *body = [nsstring stringwithformat:@"happy day!: %i. ", _score]; [textcomposer setbody:body]; uiviewcontroller *vc = self.view.window.rootviewcontroller; [vc presentviewcontroller: textcomposer animated: yes completion:nil]; } else { nslog(@"cant send text!"); } }
here dismiss code:
-(void)messagecomposeviewcontroller:(mfmessagecomposeviewcontroller *)controller didfinishwithresult:(messagecomposeresult)result { uiviewcontroller *vc = self.view.window.rootviewcontroller; [vc dismissviewcontrolleranimated:yes completion:null]; }
edit 3
the following code gives me nslog @ correct times, not dismiss window.
- (void)messagecomposeviewcontroller:(mfmessagecomposeviewcontroller *)controller didfinishwithresult:(messagecomposeresult)result { uiviewcontroller *vc = self.view.window.rootviewcontroller; // notifies users errors associated interface switch (result) { case messagecomposeresultcancelled: nslog(@"result: sms sending canceled"); break; case messagecomposeresultsent: nslog(@"result: sms sent"); break; case messagecomposeresultfailed: nslog(@"result: sms sending failed"); break; default: nslog(@"result: sms not sent"); break; } [vc dismissviewcontrolleranimated:yes completion:null]; }
if refer mfmessagecomposeviewcontroller class reference see need present modally using presentmodalviewcontroller:animated:
. responsible dismissing via delegate object once done.
i suggest have @ message composer sample code example of using mfmessagecomposeviewcontroller
class.
update
you can dismiss view controller passed delegate method -
- (void)messagecomposeviewcontroller:(mfmessagecomposeviewcontroller *)controller didfinishwithresult:(messagecomposeresult)result { // notifies users errors associated interface switch (result) { case messagecomposeresultcancelled: nslog(@"result: sms sending canceled"); break; case messagecomposeresultsent: nslog(@"result: sms sent"); break; case messagecomposeresultfailed: nslog(@"result: sms sending failed"); break; default: nslog(@"result: sms not sent"); break; } [controller dismissviewcontrolleranimated:yes completion:null]; }
Comments
Post a Comment