如何从objc中的多个元素数组中获取设备令牌?

时间:2016-07-15 06:18:03

标签: ios objective-c rtf

我有一个这样的数组(在控制台中打印): -

"DeviceToken\\uc0\\u82326E7A915B6A5CBC0E3EFF2F05F16018ED143F0EC437C12C7F83E8F8ADCCAD07E3\\u8232Created\\u82323\\'a0weeks,4\\'a0daysago\\u8232LastRegistration\\u82323\\'a0weeks,4\\'a0daysago\\u8232Status\\u8232Inactive\\u8232Alias\\u8232None\\u8232Tags\\u8232None\\u8232\\u8232\\",
"DeviceToken\\uc0\\u82320EF3D38E46243D726E7800B480AC971CDDD8D00A0FFC46029662BC6F3A629F24\\u8232Created\\u82321\\'a0monthago\\u8232LastRegistration\\u82322\\'a0days,8\\'a0hoursago\\u8232Status\\u8232Inactive\\u8232Alias\\u8232None\\u8232Tags\\u8232None\\u8232\\u8232\\",

依旧......

实际上这是从rtf文件到数组的转换。现在我想只显示设备令牌,而不是完整信息。我该如何实施呢?

2 个答案:

答案 0 :(得分:0)

iOSLearner我试图只从数组中获取令牌。我得到了解决方案。

NSMutableArray *arrayToken = [[NSMutableArray alloc]initWithObjects:@"DeviceToken\\uc0\\u82326E7A915B6A5CBC0E3EFF2F05F16018ED143F0EC437C12C7F83E8F8ADCCAD07E3\\u8232Created\\u82323\\'a0weeks,4\\'a0daysago\\u8232LastRegistration\\u82323\\'a0weeks,4\\'a0daysago\\u8232Status\\u8232Inactive\\u8232Alias\\u8232None\\u8232Tags\\u8232None\\u8232\\u8232\\",@"DeviceToken\\uc0\\u82320EF3D38E46243D726E7800B480AC971CDDD8D00A0FFC46029662BC6F3A629F24\\u8232Created\\u82321\\'a0monthago\\u8232LastRegistration\\u82322\\'a0days,8\\'a0hoursago\\u8232Status\\u8232Inactive\\u8232Alias\\u8232None\\u8232Tags\\u8232None\\u8232\\u8232\\",nil];
NSLog(@"The arrayTokens are-%@",arrayToken);
NSMutableArray *arrayExactToken = [[NSMutableArray alloc]init];
for(int i=0;i<arrayToken.count;i++)
{
    NSString *strTokenObject = [NSString stringWithFormat:@"%@",[arrayToken objectAtIndex:i]];
    NSLog(@"The token is - %@",strTokenObject);
    NSString *strNew = [NSString stringWithFormat:@"%@", [[strTokenObject componentsSeparatedByString:@"\\"] objectAtIndex:2]];
    strNew = [strNew substringFromIndex:5];
    NSLog(@"The strNew is - %@",strNew);
    [arrayExactToken addObject:strNew];
}
NSLog(@"The tokens are - %@",arrayExactToken);

打印结果

The tokens are - (
6E7A915B6A5CBC0E3EFF2F05F16018ED143F0EC437C12C7F83E8F8ADCCAD07E3,
0EF3D38E46243D726E7800B480AC971CDDD8D00A0FFC46029662BC6F3A629F24
)

答案 1 :(得分:0)

好的,所以你有一个与你的应用程序捆绑在一起的文件,而你在运行时解析它时遇到了问题。因此,解决方案是将设备ID捆绑为不同的文件格式,并将其打包到您的应用程序中(代替.rtf文件或代替.rtf文件)。

您可以在构建期间(如果输入package com.catutorial.vatbd; import android.app.ActionBar; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.webkit.WebSettings; import android.webkit.WebView; import android.widget.ShareActionProvider; import com.google.android.gms.ads.AdListener; import com.google.android.gms.ads.AdRequest; import com.google.android.gms.ads.AdView; import com.google.android.gms.ads.InterstitialAd; public class MainActivity extends Activity { InterstitialAd mInterstitialAd; private InterstitialAd interstitial; private WebView mWebView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); AdView mAdView = (AdView) findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder().build(); mAdView.loadAd(adRequest); interstitial = new InterstitialAd(this); interstitial.setAdUnitId(getString(R.string.admob_interstitial_id)); interstitial.loadAd(adRequest); interstitial.setAdListener(new AdListener() { public void onAdLoaded() { displayInterstitial(); } }); mWebView = (WebView) findViewById(R.id.activity_main_webview); WebSettings webSettings = mWebView.getSettings(); webSettings.setJavaScriptEnabled(true); mWebView.loadUrl("http://tax.catutorial.com"); mWebView.setWebViewClient(new com.catutorial.vatbd.MyAppWebViewClient(){ @Override public void onPageFinished(WebView view, String url) { //hide loading image findViewById(R.id.progressBar1).setVisibility(View.GONE); //show webview findViewById(R.id.activity_main_webview).setVisibility(View.VISIBLE); }}); } @Override public void onBackPressed() { if(mWebView.canGoBack()) { mWebView.goBack(); } else { super.onBackPressed(); } } private ShareActionProvider mShareActionProvider; @Override public boolean onCreateOptionsMenu(Menu menu) { /** Inflating the current activity's menu with res/menu/items.xml */ getMenuInflater().inflate(R.menu.menu_main, menu); /** Getting the actionprovider associated with the menu item whose id is share */ mShareActionProvider = (ShareActionProvider) menu.findItem(R.id.share).getActionProvider(); /** Setting a share intent */ mShareActionProvider.setShareIntent(getDefaultShareIntent()); return super.onCreateOptionsMenu(menu); } /** Returns a share intent */ private Intent getDefaultShareIntent(){ Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, "VAT and Tax rate of Bangladesh"); intent.putExtra(Intent.EXTRA_TEXT," Visit catutorial.com for CA suggestion"); return intent; } public void displayInterstitial() { // If Ads are loaded, show Interstitial else show nothing. if (interstitial.isLoaded()) { interstitial.show(); } } } 文件经常更改)或手动(如果它不经常更改)执行此操作。

您可以选择多种文件格式来将设备ID存储在应用包中:

  • 文本文件(每个设备ID一行)。
  • Plist文件(设备ID数组)。
  • sqlite文件(设备ID表)。

所有这些格式都易于在运行时处理。

所以这不是您问题的技术答案。我的答案是首先避免这个问题,让自己的生活变得轻松。