小编Ben*_*riu的帖子

MFMessageComposeViewController iOS7 addAttachmentData:typeIdentifier:filename:not working

我想在iOS7上将图像附加到MMS上.我写了以下代码:

    MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init];
    messageController.messageComposeDelegate = self;

    NSData *imgData = [NSData dataWithContentsOfFile:@"blablabla"];
    BOOL didAttachImage = [messageController addAttachmentData:imgData typeIdentifier:@"public.data" filename:@"image"];

    if (didAttachImage)
    {
        // Present message view controller on screen
        [self presentViewController:messageController animated:YES completion:nil];
    }
    else
    {
        UIAlertView *warningAlert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                               message:@"Failed to attach image"
                                                              delegate:nil
                                                     cancelButtonTitle:@"OK"
                                                     otherButtonTitles:nil];
        [warningAlert show];
        return;
    }
Run Code Online (Sandbox Code Playgroud)

问题是,当显示SMS屏幕时,它无法识别图像,也无法发送.我看到这样的事情:

消息屏幕

我相信这与我发送的imgData或者typeIdentifier有关.

注意:我尝试了几乎所有可能的typeIdentifiers:@"public.data",@"public.image",@"public.item",...等没有工作.

有人可以帮帮我吗?你使用的typeIdentifier是什么?我在iPhone 5,iOS 7.0.2上测试.

谢谢.


解:

正如Greg指示的那样,这解决了我的问题:将文件名设置为@"image.png",将typeIdentifier设置为kUTTypePNG.

[messageController addAttachmentData:imgData typeIdentifier:(NSString *)kUTTypePNG filename:@"image.png"];
Run Code Online (Sandbox Code Playgroud)

谢谢格雷格.

mms uti ios mfmessagecomposeviewcontroller ios7

19
推荐指数
1
解决办法
1万
查看次数

故事板方向支持xCode 4.2?

我升级到了xCode 4.2,它是新的Storyboard功能.但是,找不到支持肖像和风景的方法.

当然,我是以编程方式完成的,有2个视图,一个用于纵向,一个用于横向,就像过去一样,并且:

if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) 
    {
        self.view = self.landscapeView;
    }
    else
    {
        self.view = self.portraitView;
    }
Run Code Online (Sandbox Code Playgroud)

但我正在寻找一种方法,以某种方式自动执行此操作.我的意思是,现在是xCode 4.2,我期待更多.谢谢大家.

==================================
临时解决方案:

我将在这里提出一个临时解决方案.我说这是暂时的,因为我还在等苹果公司做一些非常聪明的事情.

我创建了另一个.storyboard文件,名为"MainStoryboard_iPhone_Landscape",并在那里实现了横向视图控制器.实际上,它与普通(肖像).storyboard完全一样,但所有屏幕都处于横向模式.

所以我将从横向故事板中提取ViewController,当轮换发生时,只需使用新的viewController视图更改self.view.

1.方向更改时生成通知:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
Run Code Online (Sandbox Code Playgroud)

2.寻找通知:

[[NSNotificationCenter defaultCenter] addObserverForName:UIDeviceOrientationDidChangeNotification object:nil queue:nil usingBlock:^(NSNotification *note) {    
    // We must add a delay here, otherwise we'll swap in the new view  
    // too quickly and we'll get an animation glitch  
    [self performSelector:@selector(updateLandscapeView) withObject:nil afterDelay:0];
}];
Run Code Online (Sandbox Code Playgroud)

3.实现updateLandscapeView

- (void)updateLandscapeView {  
 //>     isShowingLandscapeView is declared in AppDelegate, …
Run Code Online (Sandbox Code Playgroud)

iphone landscape storyboard device-orientation xcode4.2

13
推荐指数
1
解决办法
1万
查看次数

如何在iOS中使用GIDSignIn和GTMOAuth2Authentication获取刷新令牌?

我正在编写一个iOS应用程序,它使用Google的GIDSignIn [1]登录用户,GTLServiceYoutube对Youtube执行查询(上传视频和检索Youtube视频列表).

这在用户首次登录时工作正常,但大约一小时后,访问令牌过期,用户由于401错误(凭据无效)而无法再使用GTLServiceYoutube执行查询.

成功登录后,我使用以下代码设置GTMOAuth2Authentication:

- (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user withError:(NSError *)error {

    if (error == nil) {
        [self setAuthorizerForSignIn:signIn user:user];
    }
    [super signIn:signIn didSignInForUser:user withError:error];
}

- (void)setAuthorizerForSignIn:(GIDSignIn *)signIn user:(GIDGoogleUser *)user {
     GTMOAuth2Authentication *auth = [[GTMOAuth2Authentication alloc] init];

    [auth setClientID:signIn.clientID];
    [auth setClientSecret:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"GoogleClientSecret"]];
    [auth setUserEmail:user.profile.email];
    [auth setUserID:user.userID];
    [auth setAccessToken:user.authentication.accessToken];
    [auth setRefreshToken:user.authentication.refreshToken];
    [auth setExpirationDate: user.authentication.accessTokenExpirationDate];
    [[UserManager sharedInstance].youTubeService setAuthorizer:auth];
}
Run Code Online (Sandbox Code Playgroud)

哪里[[UserManager sharedInstance].youTubeService是GTLServiceYouTube的一个实例.

唯一的问题是GTLServiceYouTube.GIDSignIn似乎处理刷新令牌,因此用户始终在首次登录后登录.但GTLOAuth2Authentication仅在首次登录时有效,并在一小时后中断.

所以我的问题是:我在这里做错了吗?或者我在刷新后遗漏了一些东西以获得GTMOAuth2Authentication中的正确访问令牌?

[1] https://developers.google.com/identity/sign-in/ios/api/interface_g_i_d_sign_in

youtube-api ios oauth-2.0 google-plus

8
推荐指数
1
解决办法
3977
查看次数

将带有变音符号的NSString转换为const char *

我花了几个小时来解决这个问题,却一无所获。抱歉,如果答案在Internet上的某个地方,我真的找不到。

我有一个NSString *header = @"ästrç";或其他来自德语,瑞典语等语言的变音符号。

我需要将其NSString转换为:

const char* cString = [header cStringUsingEncoding: NSASCIIStringEncoding];
Run Code Online (Sandbox Code Playgroud)

注意:NSASCIIStringEncodingNSMacOSRomanStringEncoding不起作用。

我也试过这个:

const char *cString = [header UTF8String];
Run Code Online (Sandbox Code Playgroud)

不工作

有谁可以帮助我吗?这很奇怪。

编辑:

“不工作”是指如果我有这些字符: 输入项

它将输出以下内容: 输出量

我不在乎NSLog。我需要const char *才能用PDF编写方法:

HPDF_Page_TextOut  (HPDF_Page    page, HPDF_REAL    xpos, HPDF_REAL    ypos, const char  *text)
Run Code Online (Sandbox Code Playgroud)

encoding diacritics char nsstring

2
推荐指数
1
解决办法
2091
查看次数