2016年3月24日 星期四

申請Apple Developer Program碰到的問題

Is awesome!
申請了Apple Developer Program(以前是叫iOS Developer Program),
也碰到了這個經典問題:

We are unable to activate your Apple Developer Program membership.


其實申請前也爬了一些文,像是姓名,住址與信用卡不同,或是填了中文資料等,
會讓申請很不順利。

所以我特別注意資料不要填錯,全程使用英文輸入,也收到了購買成功的訊息。
(疑?跟以前比好像更貴了,不過這不是重點)

接著就等收啟動信了,但等了一天沒收到。
於是登入會員中心後,就發現上面的錯誤訊息了,看時間客服都下班了。
明天再打電話去問吧,而且從頭到尾也沒收到啟動的通知

雖然很多文章都說留言或寄信沒用,不過我還是先用了線上回報,反應了這個問題。
結果隔天就收到信了,大意就是帳號已開通,可以使用。

反正帳號能用,所以最後連電話也不用打了,希望大家申請時比我順利。

2016年3月19日 星期六

cocos2d-X接入UnityAds(iOS版)

1.去官網註冊,取得廣告的GAME ID,並下載sdk,解壓縮後放好,選framework會用到,

2.在Xcode專案下的General->Linked Frameworks and Libraries增加以下項目
CFNetwork.framework
CoreFoundation.framework
UnityAds.bundle
UnityAds.framework
StoreKit.framework
AdSupport.framework
SystemConfiguration.framework
CoreTelephony.framework
CoreMedia.framework


3.在Xcode專案下的Build Settings->Search Paths->Framework Search Paths
加上UnityAds.Bundle所在的目錄,不然之後會出現UnityAds/UnityAds.h' file not found


4.修改AppController.h

#import <UIKit/UIKit.h>

#import <UnityAds/UnityAds.h>//<---新增這行

@class RootViewController;

//注意下面紅色新增的字符
@interface AppController : NSObject <UIApplicationDelegate,UnityAdsDelegate> {
    UIWindow *window;
}

@property(nonatomic, readonly) RootViewController* viewController;


@end

5.修改AppController.mm

先找到下面這幾行:
    // Use RootViewController manage CCEAGLView     _viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];    _viewController.wantsFullScreenLayout = YES;    _viewController.view = eaglView;

接著往後加這幾行(注意紅色的數字,替換成自己的廣告Game ID):
    //Unity Ads
    [[UnityAds sharedInstance] setTestMode:YES];//測試時打開
    [[UnityAds sharedInstance] setDebugMode:YES];//測試時打開
    [[UnityAds sharedInstance] startWithGameId:@"1234567" andViewController:_viewController];
    [[UnityAds sharedInstance] setDelegate:self];
然後在這個檔案找個合適的地方加上這個函式(廣告播完後會到這):
    - (void)unityAdsVideoCompleted:(NSString *)rewardItemKey skipped:(BOOL)skipped
    {
    
    }

6.增加UnityAdsWrapper.h到專案內(跟AppController.h放同目錄)
    class UnityAdsWrapper
    {
    public:
        static bool canShow();
        static void show();
    };

7.增加UnityAdsWrapper.mm到專案內(跟UnityAdsWrapper.h放同目錄)
    #import <Foundation/Foundation.h>
    #import <UnityAds/UnityAds.h>
    #import "UnityAdsWrapper.h"

    bool UnityAdsWrapper::canShow()
    {
        if ([[UnityAds sharedInstance] canShow] && [[UnityAds sharedInstance] canShowAds]) {
            return true;
        } else {
            return false;
        }
    }
    void UnityAdsWrapper::show()
    {
        [[UnityAds sharedInstance] show];
    }
    void UnityAdsWrapper::hide()
    {
        [[UnityAds sharedInstance] hide];
    }

8.然後就可以在模擬器測試了,別忘了加入#include "UnityAdsWrapper.h"
    然後用以下程式碼測試:
    if(UnityAdsWrapper::canShow()){
        UnityAdsWrapper::show();
    }



2016年2月29日 星期一

在android studio編譯cocos2d-x

雖然在專案目錄下直接下指令cocos compile -p android —android-studio就可以編譯程式,若可在android studio內直接按快速鍵^R立即編譯就更方便了。

安裝的版本:
cocos v3.10
android studio 1.5.1


先選擇Run->Edit Configurations


再選擇專案,這裡的範例是mytest4


同樣的畫面下方注意到Before launch: 這個區塊有個+號,按下去


選第一個Run External tool


各欄位填入
Name: Cocos compile
Program: cocos
Parameters: compile -p android —no-apk —android-studio
Working directory: $ProjectFileDir$ 

然後按下ok就完成了。但這裡還有個地方要注意,要把新增的Cocos compile移到
Gradle-aware Make的上方,就像第三張圖那樣,編譯時就會先跑c++,再包成apk。

2015年3月19日 星期四

新增一個Model Comment

配合post,增加comment功能,從上手指南7開始。
要注意一下中文的指南還是舊的,照著做會出錯的,大約從英文版的指南 6.4 Generating a Controller
開始看,再對照修改一下,以下列出重點。
先來產生 Model

rails generate model Comment commenter:string body:text post:references

沒有用到scaffolding,只建了model

/////////////////////////////////////////////////////////////////////////

CommentsController.rb的內容改成如下:
class CommentsController < ApplicationController
  def create
    @post = Post.find(params[:post_id]) #是這篇留言所屬的文章
    @comment = @post.comments.create(comment_params) #留言本身
    redirect_to post_path(@post) #最後回到show action顯示 app/views/posts/show.html.erb
  end
private
  def comment_params
    params.require(:comment).permit(:commenter, :body)
  end
end

////////////////////////////////////////////////////////////

app/views/posts/show.html.erb 增加了留言的顯示與輸入

<h2>Comments</h2>
<% @post.comments.each do |comment| %>
  <p>
    <b>Commenter:</b>
    <%= comment.commenter %>
  </p>
  <p>
    <b>Comment:</b>
    <%= comment.body %>
  </p>
<% end %>

<%= form_for([@post, @post.comments.build]) do |f| %>
  <div class="field">
    <%= f.label :commenter %><br />
    <%= f.text_field :commenter %>
  </div>
  <div class="field">
    <%= f.label :body %><br />
    <%= f.text_area :body %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

然後文章跟留言都可以運作,接著依指南往下做就好了。

2015年3月13日 星期五

理解 posts_controller.rb

抓幾行來理解一下:

before_action :set_post, only: [:show, :edit, :update, :destroy]

before_action 意思就是執行其它的action前要先執行指定的method,這裡就是set_post,
後面的only是限定要作用的action。

//////////////////////////////////////////////////////////////////

def index
    @posts = Post.all
end

進了Blog就是執行這個action,這裡把@posts設定好後,就會拿app/views/posts/index.html.erb
來顯示了。

//////////////////////////////////////////////////////////////////

def post_params
    params.require(:post).permit(:name, :title, :content)
end

params是http request所傳來一部份的值。
這可以取得post這個model的參數,後頭的permit是限定只取哪些參數

//////////////////////////////////////////////////////////////////

def create
    @post = Post.new(post_params) #取到的參數就可以實例化一個Post物件了。

//////////////////////////////////////////////////////////////////

respond_to do |format|
依請求的格式,返回不同的數據,如下:
format.html { redirect_to @post, notice: 'Post was successfully created.' }
format.json { render :show, status: :created, location: @post }

redirect_to和render是回應瀏覽器的方式
redirect_to @post 指示瀏覽器對一個 rul 再次發出請求,例如這邊是相當於讓瀏覽器執行 http://localhost:3000/posts/1 ,
render :show 就是把 show.html.erb 解析為html回傳給瀏覽器