【问题标题】:What is the equivalent of NSString stringWithFormat in Xamarin.iOSXamarin.iOS 中 NSString stringWithFormat 的等价物是什么
【发布时间】:2015-12-11 08:30:19
【问题描述】:

我正在使用 Azure 通知中心发送通知。我希望这些通知是多语言的,但我找不到

NSString* jsontemplate= [NSString stringWithFormat:@"{\"aps\":
{\"alert\":\"$(News_%@)\"},\"inAppMessage\":\"$(News_%@)\"}",
localeString, localeString];

在函数中使用

Hub.RegisterTemplateAsync(deviceToken,name,jsontemplate,expirytemplate,tags, 
(errorCallback) => {
  if (errorCallback != null)
    Console.WriteLine("RegisterNativeAsync error: " +  errorCallback.ToString());                });

这将替换下面代码 sn-p 中的 Hub.RegisterNativeAsync 函数,我现在拥有它,它适用于简单的通知。

public override void RegisteredForRemoteNotifications(UIApplication     application, NSData deviceToken)
    {
        Hub = new SBNotificationHub(TnOConstants.AzureListenConnectionString, TnOConstants.AzureNotificationHubName);

        Hub.UnregisterAllAsync (deviceToken, (error) => {
            if (error != null)
            {
                Console.WriteLine("Error calling Unregister: {0}", error.ToString());
                return;
            }

            string[] tag = new string[]{"tnoios", "ios-"+ appVersion.ToString()};

            NSSet tags = new NSSet(tag);
            Hub.RegisterNativeAsync(deviceToken, tags, (errorCallback) => {
                if (errorCallback != null)
                    Console.WriteLine("RegisterNativeAsync error: " + errorCallback.ToString());
            });
        });
    }

我正在关注这个教程https://azure.microsoft.com/en-us/documentation/articles/notification-hubs-ios-send-localized-breaking-news/

【问题讨论】:

  • 如果您使用的是 C#,则等价于 string.Format("{0}{1}", firstArg, secondArg);

标签: objective-c azure push-notification xamarin.ios azure-notificationhub


【解决方案1】:

我最终使用 String.Format() 作为上述短语的 NSString stringWithFormat 的等效模板是:

string template = String.Format(@"{""aps"":{""alert"":""$({0})""}}", localeString);

【讨论】:

    猜你喜欢
    • 2014-05-08
    • 1970-01-01
    • 2014-06-12
    • 1970-01-01
    • 2022-11-28
    • 2021-06-19
    • 2012-07-20
    • 2023-03-30
    • 2011-04-08
    相关资源
    最近更新 更多